금융 거래 기록 흐름 공통화
This commit is contained in:
@@ -118,73 +118,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
'save_as_defaults' => !empty($_POST['save_as_defaults']) ? 1 : 0,
|
||||
];
|
||||
|
||||
$transactionType = $form['transaction_type'];
|
||||
$accountId = (int)$form['account_id'];
|
||||
$categoryId = (int)$form['category_id'];
|
||||
$amount = (float)str_replace(',', '', $form['amount']);
|
||||
$transactionDate = $form['transaction_date'];
|
||||
$merchantName = $form['merchant_name'];
|
||||
$description = $form['description'];
|
||||
$relatedAccountId = $form['related_account_id'] > 0 ? (int)$form['related_account_id'] : null;
|
||||
|
||||
$isInstallment = (int)$form['is_installment'];
|
||||
$installmentMonths = $form['installment_months'] !== '' ? (int)$form['installment_months'] : null;
|
||||
$installmentInterestRate = $form['installment_interest_rate'] !== '' ? (float)$form['installment_interest_rate'] : 0.0;
|
||||
$installmentInterestTotal = $form['installment_interest_total'] !== ''
|
||||
? (float)str_replace(',', '', $form['installment_interest_total'])
|
||||
: null;
|
||||
$installmentTotalBilled = $form['installment_total_billed'] !== ''
|
||||
? (float)str_replace(',', '', $form['installment_total_billed'])
|
||||
: null;
|
||||
|
||||
if ($amount <= 0) {
|
||||
throw new RuntimeException('금액은 0보다 커야 합니다.');
|
||||
}
|
||||
|
||||
if (!in_array($transactionType, ['income', 'expense', 'transfer', 'card_payment'], true)) {
|
||||
throw new RuntimeException('거래 유형이 올바르지 않습니다.');
|
||||
}
|
||||
|
||||
if ($accountId <= 0) {
|
||||
throw new RuntimeException('주 계좌/카드를 선택하세요.');
|
||||
}
|
||||
|
||||
if ($categoryId <= 0) {
|
||||
throw new RuntimeException('카테고리를 선택하세요.');
|
||||
}
|
||||
|
||||
if (in_array($transactionType, ['transfer', 'card_payment'], true) && !$relatedAccountId) {
|
||||
throw new RuntimeException('관련 계좌를 선택해야 합니다.');
|
||||
}
|
||||
|
||||
if ($relatedAccountId && $relatedAccountId === $accountId) {
|
||||
throw new RuntimeException('주 계좌와 관련 계좌는 같을 수 없습니다.');
|
||||
}
|
||||
|
||||
if ($transactionType !== 'expense') {
|
||||
$isInstallment = 0;
|
||||
$installmentMonths = null;
|
||||
$installmentInterestRate = 0.0;
|
||||
$installmentInterestTotal = null;
|
||||
$installmentTotalBilled = null;
|
||||
}
|
||||
|
||||
create_transaction([
|
||||
'user_id' => $uid,
|
||||
'account_id' => $accountId,
|
||||
'category_id' => $categoryId,
|
||||
'transaction_type' => $transactionType,
|
||||
'amount' => $amount,
|
||||
'transaction_date' => $transactionDate,
|
||||
'merchant_name' => $merchantName !== '' ? $merchantName : null,
|
||||
'description' => $description !== '' ? $description : null,
|
||||
'related_account_id' => $relatedAccountId,
|
||||
'is_installment' => $isInstallment,
|
||||
'installment_months' => $installmentMonths,
|
||||
'installment_interest_rate' => $installmentInterestRate,
|
||||
'installment_interest_total' => $installmentInterestTotal,
|
||||
'installment_total_billed' => $installmentTotalBilled,
|
||||
]);
|
||||
$payload = build_transaction_payload_from_input($form, $uid);
|
||||
$transactionType = $payload['transaction_type'];
|
||||
$accountId = (int)$payload['account_id'];
|
||||
$categoryId = (int)$payload['category_id'];
|
||||
$merchantName = (string)($payload['merchant_name'] ?? '');
|
||||
$relatedAccountId = $payload['related_account_id'] ? (int)$payload['related_account_id'] : null;
|
||||
$isInstallment = (int)$payload['is_installment'];
|
||||
$installmentMonths = $payload['installment_months'];
|
||||
$installmentInterestRate = (float)$payload['installment_interest_rate'];
|
||||
|
||||
create_transaction($payload);
|
||||
|
||||
if ($form['save_as_defaults']) {
|
||||
$save = [
|
||||
@@ -877,4 +821,4 @@ require __DIR__ . '/../app/views/header.php';
|
||||
})();
|
||||
</script>
|
||||
|
||||
<?php require __DIR__ . '/../app/views/footer.php'; ?>
|
||||
<?php require __DIR__ . '/../app/views/footer.php'; ?>
|
||||
|
||||
Reference in New Issue
Block a user