<?php
include("serive/samparka.php");
include("truki.php");

$currentDate = date('Ymd');
$timeInSeconds = time() % 86400;
$sequenceNumber = intval($timeInSeconds / 30);
$uniqueSequence = str_pad($sequenceNumber, 4, '0', STR_PAD_LEFT);
$bartamankalakrama = $currentDate . "10304" . $uniqueSequence;
$bartamankalakrama = $bartamankalakrama + 1;

$prathama = $bartamankalakrama;
$tarika = date('Y-m-d H:i:s');

$dekhakalakrama = mysqli_query($conn, "SELECT atadaaidi FROM `gelluonduhogu_trxu` ORDER BY kramasankhye DESC LIMIT 1");
$kaladhadi = mysqli_num_rows($dekhakalakrama);
$kalakramadhadi = mysqli_fetch_array($dekhakalakrama);

if ($kaladhadi == 0) {
    mysqli_query($conn, "INSERT INTO `gelluonduhogu_trx10` (`atadaaidi`,`dinankavannuracisi`) VALUES ('".$bartamankalakrama."','".$tarika."')");
} else if ($prathama > $kalakramadhadi['atadaaidi']) {
    mysqli_query($conn, "TRUNCATE TABLE `gelluonduhogu`");
    mysqli_query($conn, "INSERT INTO `gelluonduhogu_trx10` (`atadaaidi`,`dinankavannuracisi`) VALUES ('".$prathama."','".$tarika."')");
} else {
    $parabartikrama = $kalakramadhadi['atadaaidi'] + 1;
    mysqli_query($conn, "INSERT INTO `gelluonduhogu_trx10` (`atadaaidi`,`dinankavannuracisi`) VALUES ('".$parabartikrama."','".$tarika."')");
}
?>
