<?
include_once('includes/top.php');
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
//$br=$_SESSION['branch'];
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
if(isset($_POST['submit']))
{
	$supname=$_REQUEST['supname'];
	$scode=$_REQUEST['scode'];
 if(strlen($supname)<=0)
  {
     print "<script> alert('In sufficient entry'); history.back(1);  </script>";
     return;
  }
$re=mysqli_query($db,"select * from sup_master where supname='$supname' and code='$scode' ") or die(mysqli_error($db));
 if(mysqli_num_rows($re)>0)
    {
     print "<script> alert('Supplier name already exists'); history.back(1);  </script>";
     return;
   }


$addr1=$_REQUEST['addr1'];
$addr2=$_REQUEST['addr2'];
$city=$_REQUEST['city'];
$addr3=$_REQUEST['addr3'];
$district=$_REQUEST['district'];
$state=$_REQUEST['state'];
$pin=$_REQUEST['pin'];
$phone1=$_REQUEST['phone1'];
$phone2=$_REQUEST['phone2'];
$email=$_REQUEST['email'];
$tin=$_REQUEST['tin'];
$cst=$_REQUEST['cst'];
$kgst=$_REQUEST['kgst'];
$web=$_REQUEST['web'];
$suptype=$_REQUEST['suptype'];
$msmetyp=$_REQUEST['msmetyp'];
$msmeno=$_REQUEST['msmeno'];
$msmetype1=$_REQUEST['msmetype1'];

 $code=substr($supname,0,3).substr(time(),7,3); 
 $code=str_replace(' ','-',$code);
 //$supname=strtoupper($supname);
 if($scode!='')
 {
 $web=$supname." (".$scode.")";  
 $acname1=$web;
  }
  else
  {
    $web=$supname;  
    $acname1=$web;
  }
 print $sql="insert into sup_master(code,supname,addr1,addr2,city,dist,stat,pin,phone1,phone2,tin,cst,email,web,branch,suptype,msmetyp,msmeno,msmetype1) values
 ('$scode','$supname','$addr1','$addr2','$city','$district','$state','$pin','$phone1','$phone2','$tin','$cst','$email','$web','$brcode','$suptype','$msmetyp','$msmeno','$msmetype1')";

 mysqli_query($db,$sql);
 
 


$re=mysqli_query($db,"select * from ledger where led='$acname1' and grp='$suptype' and brcode='$brcode'") or die(mysqli_error($db));
 if(mysqli_num_rows($re)>0)
    {
     //print "<script> alert('Supplier A/c already exists'); history.back(1);  </script>";
     //return;
   }
else
{
 $sql="insert into ledger(led,grp,op,drcr,code,brcode) values('$acname1','$suptype','0','Cr','$scode','$brcode')";
 mysqli_query($db,$sql) or die(mysqli_error($db));
}

if($cst>0)
 {
 $re=mysqli_query($db,"select * from partymaster where gst='$cst' ") or die(mysqli_error($db));
 if(mysqli_num_rows($re)<=0)
    {
     $sql1="insert into partymaster (brcode,code,cname,addr1,dist1,state1,pin1,phone1,phone2,email,gst,pan,ptype) 
                 values('$brcode','$scode','$supname','$addr1','$district','$state','$pin','$phone1','$phone2','$email','$cst','$pan','SUP')";
 	     // print "$sql1<br>";
 	       mysqli_query($db,$sql1) or die('Insert Err1:'.mysqli_error($db));

   }
}


}
?>
<title></title>
    <script type="text/javascript" src="scripts/jquery-latest.js"></script>
	<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link href="css/form.css" type="text/css" rel="stylesheet" media="screen" />
    <script type="text/javascript">
        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
    </script>

<script type="text/javascript">

/***********************************************
* Disable "Enter" key in Form script
* This notice must stay intact for use
***********************************************/
                
function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}      

</script>
<style>
#txt{
font-family: Arial, Helvetica;
background-color: #F2F2F2;

}
</style>

<body background="back_ground.jpg">
<table class='container' style="background-color:#E0F8EC"><tr><td>
<font style="font-family: 'Trebuchet MS',Verdana,Helvetica,sans-serif; font-size:15px;">  &nbsp;&nbsp;Master >> Supplier</font>
<br>
<CENTER>

<FORM ACTION='<?print $PHP_SELF?>' METHOD='POST'>

<table cellspacing=1 cellpadding=1  class='form' >
<tr ><td align=center>
<table>
<tr><td colspan=2 align=center bgcolor='steelblue'><font color='ivory'>SUPPLIER MASTER</font></TD></TR>
<tr style={background:yellow}><td>Supplier Name <BR>
 <FONT SIZE=1 color=red>(Non editable)</font></td>
  <td><input type=text name='supname' size=40 onKeyDown=chkey(this); style={color:red} title='As it will create A/c head, it cannot be edited'></td></tr>
<tr style={background:yellow}><td>SAP CODE <BR>
 <FONT SIZE=1 color=red></font></td>
  <td><input type=text name='scode' size=40 onKeyDown=chkey(this); style={color:red} ></td></tr>
<tr bgColor='c1d7bb'><td>Sup Type </td><td><select name='suptype'>
<option value='Sundry Creditors'>Sundry Creditors</option>
<option value='SUNDRY CREDITORS OTHERS'>SUNDRY CREDITORS OTHERS</option>
<option value='SUNDRY CREDITORS EXPENSE'>SUNDRY CREDITORS EXPENSE</option>
</select>
</td></tr>

<tr ><td>Address1 </td><td><input type=text name='addr1' size=40 onKeyPress='return handleEnter(this, event)'></td></tr>


<tr><td>State</td><td><select name='state' id=state><option>Kerala</option><option>Tamil Nadu</option><option>Karnataka</option><option>Andhra Pradesh</option>
<option>Arunachal Pradesh</option><option>Assam</option><option>Bihar</option><option>Chandigarh</option><option>Chhattisgarh</option>
<option>Dadra and Nagar Haveli</option><option>Daman and Diu</option><option>Delhi</option><option>Goa</option>
<option>Gujarat</option><option>Haryana</option><option>Himachal Pradesh</option><option>Jammu and Kashmir</option>
<option>Jharkhand</option><option>Madhya Pradesh</option><option>Maharashtra</option><option>Manipur</option>
<option>Meghalaya</option><option>Mizoram</option><option>Nagaland</option><option>Orissa</option>
<option>Puducherry</option><option>Punjab</option><option>Rajasthan</option><option>Sikkim</option><option>Telangana</option>
<option>Tripura</option><option>Uttar Pradesh</option><option>Uttarakhand</option><option>West Bengal</option>
    </select>
</td></tr>


<tr ><td>Bank Name</td><td><input type=text name='addr2' size=40 onKeyPress='return handleEnter(this, event)'></td></tr>
<tr ><td>Branch</td><td><input type=text name='city' size=40 onKeyPress='return handleEnter(this, event)'></td></tr>
<tr ><td>Account No</td><td><input type=text name='district' size=40 onKeyPress='return handleEnter(this, event)'></td></tr>
<tr ><td>Pin No </td><td><input type=text name='pin' size=40 onKeyPress='return handleEnter(this, event)'></td></tr>
<tr ><td>Phone1 </td><td><input type=text name='phone1' size=40 onKeyPress='return handleEnter(this, event)'></td></tr>
<tr ><td>PAN NO </td><td><input type=text name='pan' size=40 onKeyPress='return handleEnter(this, event)'></td></tr>

<tr ><td>Tin NO </td><td><input type=text name='tin' size=40 onKeyPress='return handleEnter(this, event)'></td></tr>
<tr ><td>GSTIN </td><td><input type=text name='cst' size=40 onKeyPress='return handleEnter(this, event)'></td></tr>
<tr><td>Email_id </td><td><input type=text name='email' size=40 onKeyPress='return handleEnter(this, event)'></td></tr>
<tr bgColor='c1d7bb'><td>MSME </td><td><select name='msmetyp'>
    <option value='NO'>NO</option>
<option value='YES'>YES</option>


</select>
</td></tr>
<tr ><td>MSME NO </td><td><input type=text name='msmeno' size=40 onKeyPress='return handleEnter(this, event)'></td></tr>
<tr bgColor='c1d7bb'><td>MSME TYPE</td><td><select name='msmetype1'>
    <option></option>
    <option value='MICRO'>MICRO</option>
<option value='SMALL'>SMALL</option>
<option value='MEDIUM'>MEDIUM</option>


</select>
</td></tr>

<TR ><TD COLSPAN=2 ALIGN=CENTER><INPUT TYPE=SUBMIT NAME= 'submit' VALUE='  SAVE  '></TD></TR>

</table>
</td></tr>
</table>

</FORM>

<?
//if(!isset($mode))$mode='desc';
//if(!isset($column))$column=" ORDER BY supname";
//if($_GET['sortby'] != "") $column = " ORDER BY ".$_GET['sortby']; 
//if($_GET['mode']=='asc')$mode='desc';if($_GET['mode']=='desc')$mode='asc';
//if($_GET['sortorder'] == "up") $ordr = "ASC"; if($_GET['sortorder'] == "down") $ordr = "DESC"; else $order = "";
$sql="select * from sup_master order by supname";

$result=mysqli_query($db,$sql)or die(mysqli_error($db));
$num=mysqli_num_rows($result);
if($num>0)
{
?>

<table cellspacing=1 cellpadding=1 border=1 class='report'>
<th>No.<th>Name&nbsp;<th>Addr1 <th>Ledger<th>State<th>Pin <th>Phone1  <th>GSTIN. <th>Email<th>MSME TYPE<th>MSME NO.<th>Action
<?
$i=1;
while($row=mysqli_fetch_row($result))
{
?>
<form name='form1' id='form1' method='POST' Action='editsupp_mast.php?icode=<? echo $row[16]; ?>'>
<tr bgColor='c1d7bb' onMouseOver=bgColor='lightsteelblue' onMouseOut=bgColor='c1d7bb' ><td><? echo $i++; ?></td><td><? echo $row[1] ?></td><td><? echo $row[2] ?></td><td><? echo $row[13] ?></td>
<td><? echo $row[6] ?></td>
<td><? echo $row[7] ?></td><td><? echo $row[8] ?></td><td><? echo $row[11] ?></td><td><? echo $row[12] ?></td><td><? echo $row[19] ?></td><td><? echo $row[18] ?></td>
<td align=center><input type=submit value='Edit' name='ed' ></td></tr>
</form>
<?
}
}
?>
</table>

</td></tr></table>
<br>
<script>
function chkey(abc)
{
 yy=abc.value
 if(yy.indexOf('  ')>-1) 
  {
    alert('Multiple space is not allowed');
    abc.value='';
  }
 if(yy.indexOf("'")>-1) 
  {
    alert("\' is not allowed");
    abc.value='';
  }

}
</script>
