<?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 * from product order by barcode") or die(mysqli_error($conn));
while ($fsale = mysqli_fetch_array($getsale)) {

    $barcode  = $fsale['barcode'];
    $itemcode = $fsale['code'];
    $itemname = $fsale['name'];
    
    mysqli_query($conn, "UPDATE `inwtran`  SET `barcode`='$barcode' where `itemcode` = '$itemcode' ") or die(mysqli_error($conn));
    mysqli_query($conn, "UPDATE `purtran`  SET `barcode`='$barcode' where `itemcode` = '$itemcode' ") or die(mysqli_error($conn));
    mysqli_query($conn, "UPDATE `saletran` SET `barcode`='$barcode' where `itemcode` = '$itemcode' ") or die(mysqli_error($conn));
    mysqli_query($conn, "UPDATE `credtran` SET `barcode`='$barcode' where `itemcode` = '$itemcode' ") or die(mysqli_error($conn));
//    mysqli_query($conn, "UPDATE `debtran`  SET `barcode`='$barcode' where `itemcode` = '$itemcode' ") or die(mysqli_error($conn));
//    mysqli_query($conn, "UPDATE `outtran`  SET `barcode`='$barcode' where `itemcode` = '$itemcode' ") or die(mysqli_error($conn));
    mysqli_query($conn, "UPDATE `damtran`  SET `barcode`='$barcode' where `itemcode` = '$itemcode' ") or die(mysqli_error($conn));
    mysqli_query($conn, "UPDATE `tranftran` SET `barcode`='$barcode' where `itemcode` = '$itemcode' ") or die(mysqli_error($conn));
    
    mysqli_query($conn, "UPDATE `transacn` SET `barcode`='$barcode' where `itemcode` = '$itemcode' ") or die(mysqli_error($conn));
}
browse("Update completed successfully"); 

