<?php

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

$zdb = $_SESSION["zdbyear_" . $dbname];
$zyear = right($zdb, 4);
$mfrdate = getzdates($zyear, 'S');
$mtodate = getzdates($zyear, 'E');


mysqli_select_db($conn, $zdb);

$getsale = mysqli_query($conn, "SELECT vouchno, total,srno from saletran order by vouchno, srno") or die(mysqli_error($conn));
while ($fsale = mysqli_fetch_array($getsale)) {

    $netamt = $fsale['total'];
    $vouchno = $fsale['vouchno'];
    $srno = $fsale['srno'];

    mysqli_query($conn, "UPDATE `transacn` SET `netamt`='$netamt' where `vouchno` = '$vouchno' and source = 'SL' and srno = '$srno' ") or die(mysqli_error($conn));
    
}
browse("Sale completed successfully"); 

$getsale_de = mysqli_query($conn, "SELECT vouchno, total, srno from deextran order by vouchno, srno") or die(mysqli_error($conn));
while ($fsale_de = mysqli_fetch_array($getsale_de)) {

    $netamt2 = $fsale_de['total'];
    $vouchno2 = $fsale_de['vouchno'];
    $srno2 = $fsale_de['srno'];

    mysqli_query($conn, "UPDATE `transacn` SET `netamt`='$netamt2' where `vouchno` = '$vouchno2' and source = 'SLDE' and srno = '$srno2'") or die(mysqli_error($conn));
    
}
browse("Deemed Sale completed successfully");
?>
