
<?
session_start();
include("../opendb.php");
include("../test.php");
include("../util/exqty.php");
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 return;
}
$d=$_REQUEST['d'];
$m=$_REQUEST['m'];
$y=$_REQUEST['y'];
$d1=$_REQUEST['d1'];
$m1=$_REQUEST['m1'];
$y1=$_REQUEST['y1'];
if(isset($_POST['show']))
{
if($brcode=='WAR950' || $brcode=='BAN831')
{
 $dt=$y.'-'.$m.'-'.$d;
 $dto=$y1.'-'.$m1.'-'.$d1;
 print "<center><h2>TELCON DAILY REPORT  SUMMARY".datetohtml($dt)." TO ".datetohtml($dto)."</h2>";

$ker=mysqli_query($db,"select brstate from branch where brcode='$brcode'");
 $kar=mysqli_fetch_array($ker);

 

$re1=mysqli_query($db,"select distinct brcode from branch where brstate='$kar[0]' and brcode='$brcode' order by brcode");
 /*$s="create table repobr (brcode varchar(25),partcode varchar(100),partname varchar(200),qty 
double(14,2),customer varchar(200)," ;*/

while($row1=mysqli_fetch_array($re1))
 {
  $brre=mysqli_query($db,"select brname,brcode from branch where brcode='$row1[0]'");
  $brrow=mysqli_fetch_array($brre);
 print "<fieldset><legend>Branch: $brrow[0]</legend>";
 $re23=mysqli_query($db,"select distinct(partcode) from spareinvoice where brcode='$row1[0]' and entrydate>='$dt' and entrydate<='$dto'order by partcode");
  print "<table border=1 width=100%>";
 print "<th>No <th width=170>Part Code <th width=450>Part Name <th width=50>Qty <th>Customer<th>SaleType <th>Location<th>Entrydate";
 $i=1;
 while($row123=mysqli_fetch_array($re23))
 {
     
 $re2=mysqli_query($db,"select partcode,partname,sum(qty),customer from spareinvoice where brcode='$row1[0]' and entrydate>='$dt' and entrydate<='$dto'and partcode='$row123[0]'order by partcode");
 //print $r=("select partcode,partname,sum(qty),customer from spareinvoice where brcode='$row1[0]' and entrydate>='$dt' and entrydate<='$dto'and partcode='$row123[0]'order by partcode");


 while($row=mysqli_fetch_array($re2))
 {
$qty=exqty1($row[partcode],$brrow[1],$user);
$loc=getloc($row[partcode],$brcode);

$grp=getpartgroup($row[partcode]);
  print "<tr><td>".$i++."</td><td>$row[partcode]</td><td>$row[partname]</td>";
  print "<td align=right>$row[2]</td><td>$row[customer]</td><td>SpareInvoice</td><td>$loc</td><td>$row[entrydate]</td></tr>";
 }
}

$re31=mysqli_query($db,"select * from jobcard where brcode='$row1[brcode]' and date>='$dt' and date<='$dto'")or die(mysqli_error($db));

 while($jrow=mysqli_fetch_array($re31))
 {
   $sql="select partcode,partname,qty from jcardparts where jcno='$jrow[jcno]' and brcode='$jrow[brcode]'";
   $jres2=mysqli_query($db,$sql)or die('err'.mysqli_error($db));
    while($jrow1=mysqli_fetch_array($jres2))
    {
$qty=exqty1($jrow1[partcode],$brrow[1],$user);
      print "<tr><td>".$i++."(jc)</td><td>$jrow1[partcode]</td><td>$jrow1[partname]</td>";
      print "<td align=right>$jrow1[qty]</td><td>$jrow[cname]</td><td>Jobcard</td><td>$qty</td><td>$jrow[jcno]</td><td>$jrow[date]</td></tr>";
    }

 }


$re23=mysqli_query($db,"select distinct(partcode) from sparetransout where brcode='$row1[0]' and entrydate>='$dt' and entrydate<='$dto'order by partcode");
while($row123=mysqli_fetch_array($re23))
 {

$re2=mysqli_query($db,"select partcode,partname,sum(qty) from sparetransout where brcode='$row1[0]' and entrydate>='$dt' and entrydate<='$dto' and partcode='$row123[0]' order by partcode");

 while($row=mysqli_fetch_array($re2))
 {
$qty=exqty1($row[partcode],$brrow[1],$user);
$loc=getloc($row[partcode],$brcode);
  print "<tr><td>".$i++."</td><td>$row[partcode]</td><td>$row[partname]</td>";
  print "<td align=right>$row[2]</td><td>-</td><td>TransferOut</td><td>$qty</td><td>$loc</td><td>$row[entrydate] </td></tr>";
 }
}


$re2=mysqli_query($db,"select * from sparepurreturn where brcode='$row1[0]' and entrydate>='$dt' and entrydate<='$dto' order by partcode");

 while($row=mysqli_fetch_array($re2))
 {
$qty=exqty1($row[partcode],$brrow[1],$user);
  print "<tr><td>".$i++."</td><td>$row[partcode]</td><td>$row[partname]</td>";
  print "<td align=right>$row[retqty]</td><td>$row[suplier]</td><td>PurchaseReturn</td><td>$qty</td><td>$row[retno]</td><td>$row[entrydate] </td></tr>";
 }


 print "</table></fieldset>";
 
 
}
}

 $dt=$y.'-'.$m.'-'.$d;
 $dto=$y1.'-'.$m1.'-'.$d1;
 print "<center><h2>TELCON DAILY REPORT FOR THE DAY FROM ".datetohtml($dt)." TO ".datetohtml($dto)."</h2>";

$ker=mysqli_query($db,"select brstate from branch where brcode='$brcode'");
 $kar=mysqli_fetch_array($ker);

 

$re1=mysqli_query($db,"select distinct brcode from branch where brstate='$kar[0]' and brcode='$brcode' order by brcode");
 /*$s="create table repobr (brcode varchar(25),partcode varchar(100),partname varchar(200),qty 
double(14,2),customer varchar(200)," ;*/

while($row1=mysqli_fetch_array($re1))
 {
  $brre=mysqli_query($db,"select brname,brcode from branch where brcode='$row1[0]'");
  $brrow=mysqli_fetch_array($brre);
 print "<fieldset><legend>Branch1: $brrow[0]</legend>";
 $re2=mysqli_query($db,"select * from spareinvoice where brcode='$row1[0]' and entrydate>='$dt' and entrydate<='$dto'order by partcode")or die(mysqli_error($db));

 print "<table border=1 width=100%>";
 print "<th>No <th width=170>Part Code <th width=450>Part Name <th width=50>Qty <th>Customer<th>SaleType<th>CurrentStock <th>Ref.No<th>Entrydate";
 $i=1;
 while($row=mysqli_fetch_array($re2))
 {
//$qty=exqty1($row[partcode],$brrow[1],$user);
  print "<tr><td>".$i++."</td><td>$row[partcode]</td><td>$row[partname]</td>";
  print "<td align=right>$row[qty]</td><td>$row[customer]</td><td>SpareInvoice</td><td>$qty</td><td>$row[invno]</td><td>$row[entrydate]</td></tr>";
 }

$re31=mysqli_query($db,"select * from jobcard where brcode='$row1[brcode]' and date>='$dt' and date<='$dto'")or die(mysqli_error($db));

 while($jrow=mysqli_fetch_array($re31))
 {
   $sql="select partcode,partname,qty from jcardparts where jcno='$jrow[jcno]' and brcode='$jrow[brcode]'";
   $jres2=mysqli_query($db,$sql)or die('err'.mysqli_error($db));
    while($jrow1=mysqli_fetch_array($jres2))
    {
//$qty=exqty1($jrow1[partcode],$brrow[1],$user);
      print "<tr><td>".$i++."</td><td>$jrow1[partcode]</td><td>$jrow1[partname]</td>";
      print "<td align=right>$jrow1[qty]</td><td>$jrow[cname]</td><td>Jobcard</td><td>$qty</td><td>$jrow[jcno]</td><td>$jrow[date]</td></tr>";
    }

 }


$re2=mysqli_query($db,"select * from sparetransout where brcode='$row1[0]' and entrydate>='$dt' and entrydate<='$dto' order by partcode");

 while($row=mysqli_fetch_array($re2))
 {
$qty=exqty1($row[partcode],$brrow[1],$user);
  print "<tr><td>".$i++."</td><td>$row[partcode]</td><td>$row[partname]</td>";
  print "<td align=right>$row[qty]</td><td>$row[to_branch]</td><td>TransferOut</td><td>$qty</td><td>$row[tr_no]</td><td>$row[entrydate] </td></tr>";
 }

$re2=mysqli_query($db,"select * from sparepurreturn where brcode='$row1[0]' and entrydate>='$dt' and entrydate<='$dto' order by partcode");

 while($row=mysqli_fetch_array($re2))
 {
$qty=exqty1($row[partcode],$brrow[1],$user);
  print "<tr><td>".$i++."</td><td>$row[partcode]</td><td>$row[partname]</td>";
  print "<td align=right>$row[retqty]</td><td>$row[suplier]</td><td>PurchaseReturn</td><td>$qty</td><td>$row[retno]</td><td>$row[entrydate] </td></tr>";
 }


 print "</table></fieldset>";
 }
return;
}// end if
?>


<center>
<form method='post' action='<?print $PHP_SELF?>'>
<table border=1>
<th colspan=2><h3>DAILY SALES REPORT - BRANCH WISE</H3></TH>
<tr><td>Date From</td><td>dd <input type=text name='d' value='<?print date('d')?>' size=2>
	mm <input type=text name='m' value='<?print date('m')?>' size=2>
	yy <input type=text name='y' value='<?print date('Y')?>' size=4>
</td></tr>
<tr><td>Date To </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></tr>


<tr><td colspan=2 align=center><input type=submit value='Show' name='show'></td></tr>
</table>
</form>

<?
print "calc...........<br>";



?>
