<? include('include.php');//包含信息?>
<?


$spbm=trim($_GET['spbm']);
$dzbh=trim($_GET['dzbh']);
$zcmoney=trim($_GET['zcmoney']);
$yqmoney=trim($_GET['yqmoney']);
//echo $kou;

$spbm=$spbm?$spbm:'802';

//echo $_SESSION["zdzhje"];
if($spbm && $dzbh)
{

if($spbm!='802')
	{
$flag=2;//为真


//判断商品编码是否存在，如果是由jbookmain.php点击读者姓名跳转过来的


//判断读者押金余额

//求出本书的借出日期，可借天数，续借天数，每日租金，可求出应付金额，
$csql="select $tbdjbook.addtime,$tbdjbook.ghrq,$tbdgroup.jcts,$tbdgroup.xjts,$tbdgroup.xjcs,$tbdgroup.mrzj,$tbdzinfo.yjje,$tbdzinfo.yxq from $tbdjbook,$tbdgroup,$tbdzinfo where $tbdzinfo.dzbh='".$dzbh."' and 
$tbdjbook.dzbh=$tbdzinfo.dzbh and $tbdjbook.spbm='".$spbm."' and $tbdzinfo.groupid=$tbdgroup.id limit 0,1";

$result=$db->query($csql);
  while($arr=$db->result_query($result))
{
$yjje=$arr['yjje'];
$yxq=$arr['yxq'];
$jcts=$arr['jcts']; //
$xjts=$arr['xjts'];
$mrzj=$arr['mrzj'];
$jcrq=$arr['addtime'];
$xjcs=$arr["xjcs"];
$ghrq=$arr['ghrq'];
}
$tone=date("Y-m-d h:i:s");  //今天
$ttwo=$yxq." 00:00:00";

if(strtotime($tone)>strtotime($ttwo)) //当前日期大于读者有效期
	{
//echo "<font color=red>该读者已过借阅有效期，请续卡。</font>";
//$flag=3;
	}


$yfje=($jcts+$xjts)*$mrzj;  //

$yfje=$zcmoney+$yqmoney;


if(($yjje-$yfje)<$_SESSION['zdzhje'])  //押金金额-本次本书应付总金额小于最低帐户金额
	{
echo "<font color=red>您的押金金额不足，请先充值。</font>";
$flag=3;
	}




	}


//type=2为借书；3为续借书；7为丢失破损，6为还书
$type=6;

//归还日期

if($flag==2) //为真
	{
		$ophsname=$_SESSION['loginusername'];
$csql="update $tbdjbook set type=6,hstime=now(),zcmoney=$zcmoney,yqmoney=$yqmoney,ophsname='".$ophsname."' where spbm='".$spbm."' and dzbh='".$dzbh."' and type<6";  //
//echo $csql;
$result=$db->query($csql);



$csql="update $tbdjbook_xhyp set type=6,hstime=now(),zcmoney=$zcmoney,yqmoney=$yqmoney,ophsname='".$ophsname."'
where spbm='".$spbm."' and dzbh='".$dzbh."' and dwbh='".$_SESSION['dwbh_xhyp']."' and type<6";//
//echo $csql;
$result=$db->query($csql);



$csql="update $tbdbookinfo set kjsl=kjsl+1 where spbm='".$spbm."'";
$result=$db->query($csql);


$csql="update $tbdbookinfo_xhyp set kjsl=kjsl+1 where spbm='".$spbm."' and dwbh='".$_SESSION['dwbh_xhyp']."'";//";
$result=$db->query($csql);



$csql="update $tbdzinfo set yjje=(yjje-$yfje) where dzbh='".$dzbh."'";
$result=$db->query($csql);


$csql="update $tbdzinfo_xhyp set yjje=(yjje-$yfje) where dzbh='".$dzbh."' and dwbh='".$_SESSION['dwbh_xhyp']."'";//";
$result=$db->query($csql);




echo "<font color=blue>还书成功</font>";
	}


$csql="select $tbdbookinfo.*,$tbdjbook.* from $tbdbookinfo,$tbdjbook where $tbdbookinfo.spbm=$tbdjbook.spbm 
and $tbdjbook.dzbh='".$dzbh."' and $tbdjbook.type<6 order by $tbdjbook.addtime desc";

$result=$db->query($csql);

?>
<link href="css/bc.css" rel="stylesheet" type="text/css">

<TABLE class=gridView id=ctl00_ContentPlaceHolder2_GridView1
      style="WIDTH: 100%; BORDER-COLLAPSE: collapse" cellSpacing=0 rules=all
      border=1 width="90%">
  <tr> 
    <td width="92" class=gridViewHeader scope=col> 
      <div align="center"><b>序号</b></div>
    </td>
    <td width="726" class=gridViewHeader scope=col> 
      <div align="center"><b>图书名称</b></div>
    </td>
    <td width="207" class=gridViewHeader scope=col> 
      <div align="center"><b>ISBN号</b></div>
    </td>
    <td width="108" class=gridViewHeader scope=col> 
      <div align="center"><b>单价</b></div>
    </td>
   
    <td width="207" class=gridViewHeader scope=col> 
      <div align="center"><b>出版社</b></div>
    </td>
  
    <td width="196" class=gridViewHeader scope=col> 
      <div align="center"><b>归还日期</b></div>
    </td>
  </tr>
  <?
  $i=0;
                       while($arr=$db->result_query($result))
{
						   $i++;
$spbm=$arr['spbm'];
$bookname=$arr['bookname'];
$isbn=$arr['isbn'];
$cbs=$arr['cbs'];
$cbsj=$arr['cbsj'];
$ssh=$arr['ssh'];
$author=$arr['author'];
$price=$arr['price'];
$cfjh=$arr['cfjh'];
$tsfl=$arr['tsfl'];
$cszl=$arr['cszl'];
$kjsl=$arr['kjsl'];
$jwname=$arr['jwname'];
$flname=$arr['flname'];


$ghrq=$arr['ghrq'];
$tone=date("Y-m-d h:i:s");
$ttwo=$ghrq." 00:00:00";
if(strtotime($tone)>strtotime($ttwo)) //当前日期大于读者有效期 {

	{$ghrq="<font color=red>".$ghrq."</font>";}




                         
                         ?>
  <tr class="tr_southidc"> 
    <td  class=gridViewItem width="92" height="30"> 
      <div align="center"> 
        <?=$i?>
      </div>
    </td>
	  
    <td  class=gridViewItem width="726" height="30"> 
      <div align="center"> 
        <?=$bookname?>
      </div>
    </td>
    <td  class=gridViewItem width="207" height="30"> 
      <?=$isbn?>
    </td>
    <td  class=gridViewItem width="108" height="30"> 
      <?=$price?>
    </td>
   
    <td  class=gridViewItem width="207" height="30"> 
      <?=$cbs?>
    </td>
   
    <td  class=gridViewItem width="196" height="30"> 
      <?=$ghrq?>
    </td>
  </tr>
  <?

                          }
                          ?>
</table>
<?
}



?>