- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
83 lines
3.0 KiB
PHP
83 lines
3.0 KiB
PHP
<?php
|
|
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
|
|
|
|
print 'estimateList와 accountList를 처리하여 세 개의 컬럼을 계산하기 위한 화면';
|
|
|
|
include '_request.php';
|
|
|
|
$tablename = 'work';
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
|
|
$pdo = db_connect();
|
|
|
|
// PDO에서 버퍼링된 쿼리를 사용하도록 설정
|
|
$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
|
|
|
|
// 이 스크립트의 메모리 제한 증가
|
|
ini_set('memory_limit', '256M');
|
|
|
|
$sql = "SELECT * FROM " . $DB . "." . $tablename;
|
|
try {
|
|
$stmh = $pdo->prepare($sql);
|
|
$stmh->execute();
|
|
$rows = $stmh->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$pdo->beginTransaction();
|
|
|
|
foreach ($rows as $row) {
|
|
// estimateList JSON 파싱
|
|
$estimateListData = json_decode($row['estimateList'], true);
|
|
|
|
$decided_estimate = 0;
|
|
$issued_amount = 0;
|
|
|
|
if (is_array($estimateListData)) {
|
|
foreach ($estimateListData as $estimate) {
|
|
if (!empty($estimate['col4'])) {
|
|
$decided_estimate = floatval(str_replace(',', '', $estimate['col4']));
|
|
$issued_amount += $decided_estimate;
|
|
}
|
|
}
|
|
}
|
|
|
|
// accountList JSON 파싱
|
|
$accountListData = json_decode($row['accountList'], true);
|
|
|
|
$totalBill = 0;
|
|
$totalDeposit = 0;
|
|
|
|
if (is_array($accountListData)) {
|
|
foreach ($accountListData as $account) {
|
|
if (!empty($account['col4'])) {
|
|
$totalBill += floatval(str_replace(',', '', $account['col4']));
|
|
}
|
|
if (!empty($account['col6'])) {
|
|
$totalDeposit += floatval(str_replace(',', '', $account['col6']));
|
|
}
|
|
}
|
|
}
|
|
|
|
// 최종 계산
|
|
$issued_receivable = $totalBill - $totalDeposit;
|
|
$total_receivable = $decided_estimate - $totalDeposit;
|
|
|
|
// 데이터베이스 업데이트
|
|
$updateSql = "UPDATE $DB.$tablename SET decided_estimate = :decided_estimate, issued_amount = :issued_amount, issued_receivable = :issued_receivable, total_receivable = :total_receivable, total_deposit = :total_deposit WHERE num = :num";
|
|
$updateStmh = $pdo->prepare($updateSql);
|
|
$updateStmh->bindValue(':decided_estimate', $decided_estimate, PDO::PARAM_STR);
|
|
$updateStmh->bindValue(':issued_amount', $totalBill, PDO::PARAM_STR);
|
|
$updateStmh->bindValue(':issued_receivable', $issued_receivable, PDO::PARAM_STR);
|
|
$updateStmh->bindValue(':total_receivable', $total_receivable, PDO::PARAM_STR);
|
|
$updateStmh->bindValue(':total_deposit', $totalDeposit, PDO::PARAM_STR);
|
|
$updateStmh->bindValue(':num', $row['num'], PDO::PARAM_INT);
|
|
$updateStmh->execute();
|
|
}
|
|
|
|
$pdo->commit();
|
|
echo "모든 레코드가 성공적으로 업데이트되었습니다.";
|
|
} catch (PDOException $Exception) {
|
|
$pdo->rollBack();
|
|
echo "오류: " . $Exception->getMessage();
|
|
}
|
|
|
|
?>
|