<?php
session_start();
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$admin = $_SESSION["admin_" . $dbname];
$salent = $_SESSION["salent"];
$maindb = "challan";
if ($_REQUEST["vouchdt"]) {
    $vouchdt = $_REQUEST["vouchdt"];
    
    $mctr = 0;
    $tnomin = 0;
    $tnohrs = 0;
    $trate = 0;
    $tamount = 0;
    $myquery = mysqli_query($conn, "Select a.*,date_format(a.vouchdt, '%d-%m-%Y') as invdt,date_format(a.frmdt, '%d-%m-%Y') as fromdt,date_format(a.todt, '%d-%m-%Y') as todt, b.name as partyname, c.name as launchname
     from `$maindb` a LEFT JOIN accmast b ON b.accode=a.accode
     LEFT JOIN launch c ON c.code=a.launch where vouchdt = '$vouchdt' order by vouchno") or die(mysqli_error($conn));
    while ($fetdet = mysqli_fetch_array($myquery)) {
        $mctr++;

        echo "<tr class='tabital clickable-row' data-href='$file?mode=edit&vouchno=$fetdet[vouchno]'>";
        echo "<td style=''>$mctr</td>";
        echo "<td style=''>$fetdet[partyname]</td>";
        echo "<td class='text-center' style=''>$fetdet[launchname]</td>";
        echo "<td class='text-center' style=' '>$fetdet[type]</td>";
        echo "<td class='text-right' style=''>$fetdet[fromdt]</td>";
        echo "<td class='text-right' style=''>$fetdet[frmtime]</td>";
        echo "<td class='text-center' style=''>$fetdet[todt]</td>";
        echo "<td class='text-right' style=''>$fetdet[totime]</td>";
        echo "<td class='text-right' style=''>$fetdet[nohrs]</td>";
        echo "<td class='text-right' style=''>$fetdet[nomin]</td>";
        echo "<td class='text-right' style=''>$fetdet[amount]</td>";
        echo "<td class='text-center' style=''><a href='$file?mode=edit&vouchno=$fetdet[vouchno]'>$fetdet[vouchno]</a></td>";
        echo "</tr>";

        $ctr++;
        $tnomin += $fetdet['nomin'];
        $tnohrs += $fetdet['nohrs'];
        $tamount += $fetdet['amount'];
    }
    echo "<tr style='background-color:white'>";
    echo "<td class='text-right' style='color:#561585;font-weight:bolder' colspan='8'>Total</td>";
    echo "<td class='text-right' style='color:#561585;font-weight:bolder'>$tnohrs</td>";
    echo "<td class='text-right' style='color:#561585;font-weight:bolder'>$tnomin</td>";
    echo "<td class='text-right' style='color:#561585;font-weight:bolder'>" . rajnumformat($tamount, 2) . "</td>";
    echo "</tr>";
} else {
    echo "No Record for this Date";
}
?>
 