<? session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}

include("../opendb.php");
include("../test.php");
?>
<script>
 function valid()
  {
    if(document.f1.newda.value.length<=2)
     {
      alert('Invalid DA');
      return false;
     }
    if(document.f1.oldda.value.length<=2)
     {
      alert('Invalid DA');
      return false;
     }
      return true;
 }
//
</script>

<style>
body,td{font-family:'arial narrow';letter-spacing:1;font-size:13}
th{background-color:c1d7bb;font-size:13}
.mnu{margin-left:5}
</style>
<center>
<form name='f1' action='<?print $PHP_SELF?>' onSubmit="return valid()">
<table>
<th colspan=2>Change DA</th>
<tr><td> Enter Old DA </td><td><input type=text name='oldda'></td></tr>
<tr><td> Enter new DA </td><td><input type=text name='newda'></td></tr>
<tr>
<th colspan=2><input type=submit value='Change' name='ch'>
</tr>
</table>
</form>
<?
if($ch)
{
  $rr=mysqli_query($db,"select * from vehopstock where dano='$newda' and brcode='$brcode'");
  if(mysqli_num_rows($rr)>0)
  {
    print "<script> alert('DA already exists in Opening stock'); </script>";
    return;
  }


  $rr=mysqli_query($db,"select * from veh_purchase where da='$newda' and brcode='$brcode'");
  if(mysqli_num_rows($rr)>0)
  {
    print "<script> alert('DA already exists in Purchase'); </script>";
    return;
  }
  $rr=mysqli_query($db,"select * from veh_invoice where da='$newda' and brcode='$brcode'");
  if(mysqli_num_rows($rr)>0)
  {
    print "<script> alert('DA already exists in Invoice'); </script>";
    return;
  }

print 'Changing.. <br>';
$re=mysqli_query($db,"update vehopstock set dano='$newda' where dano='$oldda' and brcode='$brcode'")or die(mysqli_error());
if(mysqli_affected_rows($db)>0)
 print " Changed veh Opening Stock <br>";

$re=mysqli_query($db,"update purorder set dano='$newda' where dano='$oldda' and brcode='$brcode'");
if(mysqli_affected_rows($db)>0)
 print " Changed veh Purchase Order Stock <br>";

$re=mysqli_query($db,"update veh_purchase set da='$newda' where da='$oldda' and brcode='$brcode'");
if(mysqli_affected_rows($db)>0)
 print " Changed Veh Purchase <br>";

$re=mysqli_query($db,"update veh_invoice set da='$newda' where da='$oldda' and brcode='$brcode'");
if(mysqli_affected_rows($db)>0)
 print " Changed Veh Invoice <br>";

$re=mysqli_query($db,"update crnote set da='$newda' where da='$oldda' and brcode='$brcode'");
if(mysqli_affected_rows($db)>0)
 print " Changed Credit Note (Discount allowed) <br>";

$re=mysqli_query($db,"update veh_transin set da='$newda' where da='$oldda' and brcode='$brcode'");
if(mysqli_affected_rows($db)>0)
 print " Changed Trans in <br>";
$re=mysqli_query($db,"update veh_transout set da='$newda' where da='$oldda' and brcode='$brcode'");
if(mysqli_affected_rows($db)>0)
 print " Changed Trans out <br>";


$re=mysqli_query($db,"update journal2 set no='$newda' where no='$oldda' and brcode='$brcode' and against='DA'");
if(mysqli_affected_rows($db)>0)
 print " Changed Accounts <br>";


}



