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

$zdb = $_SESSION["zdbyear_" . $dbname];
$zyear = right($zdb, 4);
mysqli_select_db($conn, $zdb);

$party = $_POST["party"];


if ($_POST["para"] == 1) {
    $fromdate = $_POST["fromdate"];
    $todate = $_POST["todate"];

    mysqli_query($conn, "DELETE FROM `logac` WHERE accode='$party' AND `todate`='$todate'") or die(mysqli_error($conn));


    mysqli_query($conn, "INSERT INTO `logac`(accode, `fromdate`, `todate`)
                VALUES('$party', '$fromdate', '$todate')")or die(mysqli_error($conn));

    mysqli_query($conn, "UPDATE `accmast` SET `ledgfrom`='$fromdate', `ledgto`='$todate' WHERE accode='$party'")or die(mysqli_error($conn));

    echo "<label class='label success' style='font-size:15px'>Date Logged Successfully</label>";
} else {
    $getdata = mysqli_query($conn, "SELECT `ledgfrom`, `ledgto` FROM `accmast` WHERE accode='$party'")or die(mysqli_error($conn));
    $data1 = mysqli_fetch_array($getdata);
    header("Content-type: application/json");
    $data = array("fromdate" => $data1['ledgfrom'], "todate" => $data1['ledgto']);
    echo json_encode($data);
}
?>
