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

$user = $_SESSION["username"];
$zdb = $_SESSION["zdbyear_$dbname"];
$stkdb = 'transacn';
$source = 'SL';
mysqli_select_db($conn, $zdb);

mysqli_query($conn, "DELETE FROM `$stkdb` WHERE `source`='$source'") or die(mysqli_error($conn));

$mstkcod = mysqli_query($conn, "SELECT a.*, b.godown FROM `saletran` a, `salemain` b where a.vouchno = b.vouchno order by a.vouchno") or die(mysqli_error($conn));
//$icod = mysqli_fetch_array($mitemcod);

while ($icod = mysqli_fetch_array($mstkcod)){
    
    $mvouch   = $icod[vouchno];
    $mvouchdt = $icod[vouchdt];
    $mbarcode = $icod[barcode];
    $msrno    = $icod[srno];
    $mitem    = $icod[itemcode];
    $mqty     = $icod[qty] * -1;
    $mrate    = $icod[rate];
    $mmrp     = $icod[mrp];
    $mamt     = $icod[amt];
    $godown   = $icod[godown];
    
    
    mysqli_query($conn, "INSERT INTO `$stkdb`(vouchno, `godown`, `vouchdt`, `source`,  srno, itemcode,  qty,
                                                    rate, amount,  mrp )
                            VALUES('$mvouch','$godown', '$mvouchdt','$source',  '$msrno', '$mitem', '$mqty',
                                   '$mrate', '$mamt', '$mmrp')") or die(mysqli_error($conn));
}


?>

</html>