<?php
// Script to backfill NIP into dokumen table based on pengajuan table
$db = mysqli_connect('localhost', 'root', '', 'simkp_asn');
if (!$db)
    die("Connection failed");

$sql = "UPDATE dokumen 
        JOIN pengajuan ON dokumen.pengajuan_id = pengajuan.id 
        SET dokumen.nip = pengajuan.target_nip 
        WHERE dokumen.nip IS NULL OR dokumen.nip = ''";

if (mysqli_query($db, $sql)) {
    echo mysqli_affected_rows($db) . " documents updated with NIP information.\n";
} else {
    echo "Error: " . mysqli_error($db) . "\n";
}
mysqli_close($db);
