<?
session_start();

include("../opendb.php");
include("../test.php");
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
	//tr{background-color:white}
	th{background-color:steelblue;color:white}
.right{text-align:right}
</style>

<center>

<?
$tbl="spareinvwar".$brcode;
//mysqli_query($db,"drop table $tbl");
//mysqli_query($db,"CREATE TABLE $tbl (warno int(10),partcode varchar(200),partname varchar(200),psnqty double(10,2), telcqty double(14,2),price double(14,2))");  


//mysqli_query($db,"delete from $tbl");

if($add)
{
$dt=date('Y-m-d');
  $res1=mysqli_query($db,"select * from $tbl where partcode='$partcode' and warno='$warno1' and brcode='$brcode'");
  if(mysqli_num_rows($res1)>0)
  {
    print "<script> alert('Duplicate Entry')</script>";
    return;
  }

 $sql="insert into $tbl values('$warno1','$partcode','$prtname','$psnqty','$telcqty', '$price','$msno','n','$dt')";
//print $sql;
 mysqli_query($db,$sql) or die(mysqli_error());
}
 
$res=mysqli_query($db,"select * from $tbl where warno='$warno1' order by partcode");
if(mysqli_num_rows($res)>0)
{
  $i=1;
  print "<table border=1 cellpadding=3> <th>No <th>Item Code <th>Item Name <th>PSN Qty <th>Telc Qty<th>Price<th> Del";
  while($row=mysqli_fetch_array($res))
  {
    print "\n<form action='$PHP_SELF'> <input type=hidden name='partcode' value='$row[1]'><tr><td>";
    print $i++."</td><td>$row[1]</td><td>$row[2]</td><td>$row[psnqty]</td>";
    print "<td>$row[telcqty]</td><td>$row[price]</td>";
    print "<td><input type=submit value='Del' name='Del'></td></tr></form>";
  }
 print "</table>";
}


if($Del)
{
 mysqli_query($db,"delete from $tbl where partcode='$partcode' and warno='$warno1'")or die('err'.mysqli_error());
log_entry($brcode,$user,$REMOTE_ADDR,"war temp del war:$warno part: $partcode");
 print "<script>document.location='invtempwar.php'</script>";
}
?>
<script>
var msn=[];
var dt=[];
function getmsno()
{
document.f1.msno.value=msn[document.f1.cust.selectedIndex];
document.f1.cdate.value=dt[document.f1.cust.selectedIndex];
}

function valid()
{
var at=document.getElementById("msno").value.indexOf(",")
if(at>0)
 {
   alert ('Invalid MSNO');
document.getElementById("msno").focus();
   return false;
 }
if(document.getElementById("msno").value.length<=0)
{
 alert('Invalid MSNO');
document.getElementById("msno").focus();
 return false;
}

if(document.f1.hmr.value.length<=0)
{
 alert('Invalid HMR');
document.f1.hmr.focus();
 return false;
}
if(document.f1.cssno.value.length<=0)
{
 alert('Invalid CSSNO');
 return false;
}
if(document.f1.notifno.value.length<=0)
{
 alert('Invalid Notif NO');
 return false;
}
}
</script>

<fieldset> <legend> Details</legend>
<form name='f1' action='upd_trnaswar.php' onSubmit="return valid()">
<?print 'War No: <input type=text name=warno12 size=5>';?>
<table border=1>
<tr><td>To </td><td colspan=10>
<?
$brres=mysqli_query($db,"select brcode,brname from branch where brname like 'serv%' order by brname");
print "<select name='tobr'>";
 while($brrow=mysqli_fetch_array($brres))
 {
   print "<option value='$brrow[0]'>$brrow[1]</option>";
 }
/*$brres1=mysqli_query($db,"select distinct code,supname from sup_master order by supname");
 while($brrow1=mysqli_fetch_array($brres1))
 {
   print "<option value='$brrow1[0]'>$brrow1[1]</option>";
 }
*/
print "</select> </td></tr>";
?>
<tr><td>Date </td><td>dd <input type=text name='d' size=2 value='<?print date('d')?>'>
mm<input type=text name='m' size=2 value='<?print date('m')?>'>
yy<input type=text name='y' size=4 value='<?print date('Y')?>'>
</td><td>Customer </td><td colspan=10>
<?
$brres=mysqli_query($db,"select acname,code from customer order by acname")or die('Cus err:'.mysqli_error());
print "<select name='cust' onChange=getmsno()>";
$i=0;
 while($brrow=mysqli_fetch_array($brres))
 {
   print "\n<option value='$brrow[0]'>$brrow[0]</option>";
   $mres=mysqli_query($db,"select msno,dcomm from minput where cust='$brrow[1]'");
   print "<script> var x=''; var y='';";
   while($mrow=mysqli_fetch_array($mres))
   {
     if(mysqli_num_rows($mres)>1)
       {
	print "\n  x=x+', '+'$mrow[0]';";
        print "\n y=y+', '+'".datetohtml($mrow[1])."';";
	}
     else if(mysqli_num_rows($mres)>0)
       {
	print "\n  x='$mrow[0]';";
         print "\n  y='".datetohtml($mrow[1])."';";
	}
    
   }
    print "msn[$i]= x; dt[$i]=y</script>";

	$i++;

 }
$brres1=mysqli_query($db,"select distinct code,supname from sup_master order by supname");
 while($brrow1=mysqli_fetch_array($brres1))
 {
   print "\n<option value='$brrow1[0]'>$brrow1[1]</option>";
 }

print "</select>";
?>
<br><br><font color=red>*</font>MSNO:
<input type=text id='msno' name="msno">
Comm Date <input type=text name='cdate'>
</td></tr>
<tr><td>Failure On</td><td>dd <input type=text name='d1' size=2 value='<?print date('d')?>'>
mm<input type=text name='m1' size=2 value='<?print date('m')?>'>
yy<input type=text name='y1' size=4 value='<?print date('Y')?>'>
</td>
<td><font color=red>*</font>HMR </td><td><input type=text name='hmr' size=4></td>
<td>Failed LR No </td><td><input type=text name='flr'></td>
<td>Transport </td><td><input type=text name='transp'></td>
<tr><td> Date </td><td>dd <input type=text name='d2' size=2 value='<?print date('d')?>'>
mm<input type=text name='m2' size=2 value='<?print date('m')?>'>
yy<input type=text name='y2' size=4 value='<?print date('Y')?>'>
</td>
<!--
<td>To </td><td>
<?
$brres1=mysqli_query($db,"select brcode,brname from branch order by brname");
print "<select name='sendto'>";
 while($brrow1=mysqli_fetch_array($brres1))
 {
   print "<option value='$brrow1[0]'>$brrow1[1]</option>";
 }
$brres2=mysqli_query($db,"select distinct code,supname from sup_master order by supname");
 while($brrow2=mysqli_fetch_array($brres2))
 {
   print "<option value='$brrow2[0]'>$brrow2[1]</option>";
 }

print "</select> </td>";
?>
-->
<td>Failure Info </td><td colspan=3><textarea name='finfo' rows=1 cols=52></textarea></td></tr>
<tr><td>CSS No</td><td><input type=text name='cssno'></td><td>Notif No</td><td><input type=text name='notifno'></td>
<td>Serv Ord</td><td><input type=text name='servord'</td>
<tr bgcolor='yellow'> <td>STO No</td><td><input type=text readonly name='stono'></td>
<td>P R No</td><td><input type=text name='preqno'></td>
<td>Inv NO. </td><td><input type=text name='invno' size=10></td>
<td>Inv Date </td><td>
dd<input type=text name='d3' size=2>
mm<input type=text name='m3' size=2>
yy<input type=text name='y3' size=4>
</td></tr>
<tr bgcolor='yellow'> <td>Satus</td><td><input type=text name='stat'></td>
<th colspan=10> <input type=submit value='Transfer to branch'></th>
</table>
</form>
</fieldset>

<script>
document.f1.warno12.value=parent.banner.document.f1.warno.value;
</script>

