<?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');

$maindb = 'item';
//$trandb = 'saletran';
mysqli_select_db($conn, $zdb);

$tran = mysqli_query($conn, "select srl,manualno,myvouch from `Sheet1` order by srl") or die(mysqli_error($conn));

$ctr = 0;
while ($gettran = mysqli_fetch_array($tran)) {
    $ctr++;
    $srl = $gettran['srl'];
    $manualno = $gettran['manualno'];
    $myvouch = $gettran['myvouch'];

    if ($myvouch == "") {
        if ($srl > 1) {
            $olsrl = $srl - 1;
            $getolsrl = mysqli_query($conn, "select srl,manualno,myvouch from `Sheet1` where srl = '$olsrl'") or die(mysqli_error($conn));
            $fetsrl = mysqli_fetch_array($getolsrl);
            $olmanualno = $fetsrl['manualno'];
            $olmyvouch = $fetsrl['myvouch'];
            mysqli_query($conn, "update `Sheet1` set `manualno` = '$olmanualno', myvouch='$olmyvouch' WHERE  srl='$srl'") or die(mysqli_error($conn));
        }
    }
}
browse('success');
?>
