<? session_start(); ?>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:c1d799}
.mnu{margin-left:5}
</style>
<?
if($submit)
{
 include("../opendb.php");
 $code=substr($brname,0,3).substr(time(),7,3); 
 $code=str_replace(' ','-',$code);
 $res=mysqli_query($db,"select * from branch where brname='$brname'");
 if(mysqli_num_rows($res)>0)
 {
  print "<script> alert('Duplicate Entry'); history.back(1);</script>";
  return;
 }
 $sql="insert into branch values('$code','".strtoupper($brname)."', '$brman','$braddr', '$brcity','$brphone','$brpass1','$btype','$tin','$cst','$brstate')";
 mysqli_query($db,$sql) or die(mysqli_error());

 $led_code='csh'.substr(time(),7,3); 
 mysqli_query($db,"insert into ledger values('Cash','Cash in hand','','Dr','$led_code','$code')") or die('1'.mysqli_error());

 $led_code='pet'.substr(time(),7,3); 
 mysqli_query($db,"insert into ledger values('Petty Cash','Cash in hand','','Dr','$led_code','$code')") or die('2'.mysqli_error());

 $led_code='out'.substr(time(),7,3); 

 mysqli_query($db,"insert into ledger values('Output tax 12.5','Output Tax','','Cr', '$led_code','$code')") or die('3'.mysqli_error());


 $led_code='otc'.substr(time(),7,3); 
 mysqli_query($db,"insert into ledger values('Output tax on credit notes 12.5','Output Tax','','Cr', '$led_code','$code')") or die('4'.mysqli_error());

 $led_code='dis'.substr(time(),7,3); 
 mysqli_query($db,"insert into ledger values('Discount allowed(vehicles)','Discount Allowed','','Dr', '$led_code','$code')") or die('5'.mysqli_error());

 $led_code='sal'.substr(time(),7,3); 
 mysqli_query($db,"insert into ledger values('Sales 12.5(vehicle)','Sales 12.5', '','Cr', '$led_code', '$code')") or die('6'.mysqli_error());

 $led_code='inp'.substr(time(),7,3); 
 mysqli_query($db,"insert into ledger values('Input tax 12.5','Input Tax','','Dr', '$led_code', '$code')") or die('7'.mysqli_error());


 $led_code='pur'.substr(time(),7,3); 
 mysqli_query($db,"insert into ledger values('Purchase 12.5(vehicle)','Purchases 12.5','','Dr', '$led_code', '$code')")or die('8'.mysqli_error());

 $led_code='sre'.substr(time(),7,3); 
 mysqli_query($db,"insert into ledger values('Sales ret 12.5(vehicle)','Sales Return','','Dr', '$led_code', '$code')") or die('9'.mysqli_error());

 $led_code='pre'.substr(time(),7,3); 
 mysqli_query($db,"insert into ledger values('Purchase ret 12.5(vehicle)','Purch. Returns','','Cr', '$led_code', '$code')") or die(mysqli_error());

 $led_code='pub'.substr(time(),7,3); 
 mysqli_query($db,"insert into ledger values('Purchase 12.5(Body)','Purchases 12.5','','Dr', '$led_code', '$code')") or die(mysqli_error());

 $led_code='pun'.substr(time(),7,3); 
 mysqli_query($db,"insert into ledger values('Purchase(Un registered)','Purchases Unreg.','','Dr', '$led_code', '$code')") or die(mysqli_error());

 $led_code='ots'.substr(time(),7,3); 
 mysqli_query($db,"insert into ledger values('Output tax 12.5 (Sale Ret)','Output Tax','','Cr', '$led_code','$code')") or die(mysqli_error());

 $led_code='ipr'.substr(time(),7,3); 
 mysqli_query($db,"insert into ledger values('Input tax 12.5 (Pur Ret)','Input Tax','','Dr', '$led_code', '$code')") or die(mysqli_error()); 

$led_code='gsc'.substr(time(),7,3); 
 mysqli_query($db,"insert into ledger values('Goods Sent on Consig.','Stock Transfer In','','Cr', '$led_code', '$code')") or die(mysqli_error()); 

 $led_code='grc'.substr(time(),7,3); 
 mysqli_query($db,"insert into ledger values('Goods recvd on Consig.','Stock Transfer Out', '','Dr', '$led_code', '$code')") or die('9'.mysqli_error());


 print "Branch and Ledgers have been Created";
}
?>

<script>
function validate()
{
var p1=document.f1.brpass1.value
var p2=document.f1.brpass2.value

 submit="true";
 if(document.f1.brname.value.length<3)
  {submit="false"; alert('Invalid branch name');}

 if(document.f1.brpass1.value.length<=0)
  {submit="false"; alert('Invalid Password');}

 if(document.f1.brpass2.value.length<=0)
  {submit="false"; alert('Invalid Password2');}
 if(p1!=p2)
  {submit="false"; alert('Passwords does not match');}

 if(submit=="false")
  return false;
}
</script>

<body bgcolor=fcfff1>
<font color=green>
<h3>Branch Creation</h3></font>
<hr bgcolor=red>
<center>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return validate()">
<table border=0  cellspacing=2 cellpadding=5>
<tr><td>Branch Name</td><td><input type=text name='brname' size=40></td></tr>
<tr><td>Branch Type </td><td><select name='btype'>
<option>Eicher</option>
<option>Telecon</option>
</select></td></tr>

<tr><td>Branch Manager</td><td><input type=text name='brman' size=40></td></tr>
<tr><td>Address</td><td><input type=text name='braddr' size=40></td></tr>
<tr><td>City</td><td><input type=text name='brcity' size=40></td></tr>
<tr><td>State</td><td>
<select name='brstate'>
<option>Kerala</option>
<option>Karnataka</option>
</select>
</td></tr>
<tr><td>Phone</td><td><input type=text name='brphone' size=40></td></tr>

<tr><td>Admin Password</td><td><input type=password name='brpass1' size=40></td></tr>
<tr><td>Confirm <br>Admin Password</td><td valign=bottom><input type=password name='brpass2' size=40></td></tr>
<tr><td>Tin</td><td><input type=text name='tin' size=40></td></tr>
<tr><td>CST</td><td><input type=text name='cst' size=40></td></tr>

<tr><td colspan=2 align=center><input type=submit name='submit' value='  S A V E  '> <input type=button value='   C A N C E L    ' onClick=document.location='main.htm'></td></tr>
</table>
</form>
<?
include("listbr.php");
?>

