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

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

$maindb = 'salemain';
$trandb = 'saletran';
$zroot = $_SESSION["zdbroot"];

/////////////   local sale

$source = 'SL' ;
$tradesale = mysqli_query($conn, "SELECT *, sum(subtot) as chkamt from saletran group by vouchno ") or die(mysqli_error($conn));
while ($fetmain = mysqli_fetch_array($tradesale)) {
       $tranamt = $fetmain[chkamt] ;
       $vouchno = $fetmain[vouchno] ;
       
       $slmain = mysqli_query($conn, "SELECT taxableamt, postamt, canc_flag from salemain WHERE vouchno =  '$vouchno'  ") or die(mysqli_error($conn));
       $ftmain = mysqli_fetch_array($slmain); 
       $mainamt = $ftmain[taxableamt] - $ftmain[postamt] ;
       $canc = $ftmain[canc_flag] ;
       if ($canc != 'C') {
           if (round($mainamt,0) != round($tranamt,0)) {
               echo $source .  ' ' . $vouchno  . "<br>";
           }
       }
}

//////////// deemed 

$source = 'SLDE' ;
$tradesale = mysqli_query($conn, "SELECT *, sum(subtot) as chkamt from deextran group by vouchno ") or die(mysqli_error($conn));
while ($fetmain = mysqli_fetch_array($tradesale)) {
       $tranamt = $fetmain[chkamt] ;
       $vouchno = $fetmain[vouchno] ;
       
       $slmain = mysqli_query($conn, "SELECT taxableamt, postamt, canc_flag from deexmain WHERE vouchno =  '$vouchno'  ") or die(mysqli_error($conn));
       $ftmain = mysqli_fetch_array($slmain); 
       $mainamt = $ftmain[taxableamt] - $ftmain[postamt] ;
       $canc = $ftmain[canc_flag] ;
       if ($canc != 'C') {
           if (round($mainamt,0) != round($tranamt,0)) {
               echo $source .  ' ' . $vouchno  . "<br>";
           }
       }
}


//////////// deemed 

$source = 'SLEX' ;
$tradesale = mysqli_query($conn, "SELECT *, sum(subtot) as chkamt from saletranexp group by vouchno ") or die(mysqli_error($conn));
while ($fetmain = mysqli_fetch_array($tradesale)) {
       $tranamt = $fetmain[chkamt] ;
       $vouchno = $fetmain[vouchno] ;
       
       $slmain = mysqli_query($conn, "SELECT grossat as taxableamt, canc_flag from salemainexp WHERE vouchno =  '$vouchno'  ") or die(mysqli_error($conn));
       $ftmain = mysqli_fetch_array($slmain); 
       $mainamt = $ftmain[taxableamt]  ;
       $canc = $ftmain[canc_flag] ;
       if ($canc != 'C') {
           if (round($mainamt,0) != round($tranamt,0)) {
               echo $source .  ' ' . $vouchno  . "<br>";
           }
       }
}


?>
