<?php
  include_once 'opendb.php';
   $mret="Error";
     
    if (isset($_POST["EntryNo"]) &&  isset($_POST["VchrType"]) &&  isset($_POST["CompID"]) )
    {
	
        $EntryNo=$_POST["EntryNo"] ;
        $VchrType=$_POST["VchrType"] ;
        $CompID=$_POST["CompID"] ;
        $tablename="stock_issue";
        $tablenamesub="stock_issue_sub";
        if ($VchrType=='STR'){
            $tablename="stock_return";
            $tablenamesub="stock_retun_sub";
        }
        if(isset($_POST["isFlagUpd"])){
            $flagupd=$_POST["isFlagUpd"];
        }
        else {
            $flagupd="0";
        }
       
        $sql = "SELECT exported FROM $tablename WHERE  comp_id=$CompID and Entry_no=$EntryNo" ;
        $sresult = $conn->query($sql);
        if ($sresult->num_rows > 0 )
        { 
               if($srow = $sresult->fetch_assoc())
                 {                   
                     if ($srow["exported"]>0) $mret="No"; else $mret="Yes";
                } 
            if($mret=="Yes"){
                if($flagupd=="1"){
                 $sql = "update $tablename set pc_edited=1 Where  comp_id=$CompID and Entry_no=$EntryNo" ;
                 $sresult = $conn->query($sql);
                }
                elseif ($flagupd=="2") {             
                 $sql = "delete from $tablename Where  comp_id=$CompID and Entry_no=$EntryNo" ;
                 $sresult = $conn->query($sql);
                 $sql = "delete from $tablenamesub Where  comp_id=$CompID and Entry_no=$EntryNo" ;
                 $sresult = $conn->query($sql);
                }
            }    
        } 
        else {
                 $mret="Yes";
        }
        
  
    }
    else
    {
        $mret = "insufficient input";
    }
    
    $conn->close();
    echo $mret;
    ?>

