<?php  
error_reporting(0);
$PageSecurity = 3;
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;
$cnp=$_REQUEST['cnp'];
	//echo $_SERVER['PHP_SELF'];
include ('includes/session.inc');
include ('includes/function_lib.php');
global $db;
   echo '<link href="'.$rootpath. '/css/'. $_SESSION['Theme'] .'/default.css" rel="stylesheet" type="text/css" />';
 if($_REQUEST['id']=='')
	  $_SESSION['ACGCurrentREF']=$_SERVER['HTTP_REFERER'];
 ?><center><h2><?php echo $fromtitle=  $s->getField('voucher_master','VoucherType',$_REQUEST['VPrefix'],'GroupName');?></h2></center>
 <?php 
if($_REQUEST['id']!='')
{
$query1="select job_card_number,job_card_date,closing_date,grandTotal,pending_amount from trouble_ticket_jobcard where id='".$_REQUEST['id']."'";
		$result1=DB_query($query1,$db);
		$myrow1=DB_fetch_array($result1) ;
		$jobcardNo=$myrow1['job_card_number'];
	 	$jobcardDate=$myrow1['job_card_date'];
		$grandTotal=$myrow1['grandTotal'];
		$pending_amount=$myrow1['pending_amount'];
}
if($_REQUEST['Submit'])
{
   	 $adjustment=$_REQUEST['adjust'];
   	 $data['service_billbookid']=$_REQUEST['id'];
	 $data['grand_total']=$grandTotal;
	 $data['adjustment']=$_REQUEST['adjust'];
	 $data['pending_amount']=$_REQUEST['grandTotal']-$adjustment;
	 $data['posted_date']=date('Y-m-d');	 
	 $data['status']=0;
	 $s->RecordInsert('account_service_billbook', $data );
	$lastid=DB_Last_Insert_ID($db,'account_service_billbook', 'id');
	$_SESSION['Sess_AInvBillBook']=$lastid; ?>
<script language='javascript'>
  	opener.window.location="<?php  echo $_SESSION['ACGCurrentREF'];?>&amount=<?php echo $adjustment;?>&cnp=<?php  echo $cnp?>";self.close(); 
	</script>
<?php } ?>
 <form action="" method="post">
 <table width="100%" border="1">
  <tr>
    <td>Job Card No &nbsp;</td>
    <td>Job Card Date</td>
    <td>Pend. Amount </td>
	<td>Adjust. Amount </td>
	<td>&nbsp; </td>
  </tr>
  <tr>
    <td>
<input name="jobcardNo" type="text"  value="<?php echo   $jobcardNo; ?>"/></td>
    <td><input name="jobcardDate" type="text" value="<?php echo $jobcardDate; ?>"/></td>
    <td><input name="grandTotal" type="grandTotal"  value="<?php echo $pending_amount ?>" /></td>
	 <td><input name="adjust" type="text"  value="" /></td> <td><input name="Submit" type="submit" value="Go" /></td>
  </tr>
</table>
</form>
<table width="100%" border="1">
  <tr>
    <th>Job Card No </th>
    <th>Job Card Date </th>
	<th>Closing Date </th>
	<th>Spare Part Amt </th>
	<th>Service Amt </th>
    <th>Amount </th>
	<th>Pending Amount</th><th></th>
  </tr>
<?php     $getClientLedger=$s->GetFieldValue('clientmaster',"ledger_id='".$_REQUEST['cnp']."'" ,'id');

    $query="select  * from trouble_ticket_jobcard where party_name='".$getClientLedger."'";
    	$result=DB_query($query,$db);
		$i=1;
		// echo (DB_num_rows($result));
	 	if(DB_num_rows($result)>0)
		{
	 		while($myrow=DB_fetch_array($result))
			{
			 // if($myrow['pending_amount']!=0){
			?>
    <tr><td><?php  echo $myrow['job_card_number']?></td>
    <td><?php  echo ConvertSQLDate($myrow['job_card_date']);?></td>
	<td><?php  echo ConvertSQLDate($myrow['closing_date']);?></td>
	<td>
	<?php $query2="select SUM(amt) AS partsum from trouble_ticket_jobcard_details where jc_id='".$myrow['id']."'";
		$result2=DB_query($query2,$db);
		$myrow2=DB_fetch_array($result2);
		if(empty($myrow2['partsum'])) {echo "0";} else {echo $myrow2['partsum'];}
		?>
	</td>
	<td>
	<?php $query3="select SUM(service_amt) AS servicesum from add_service_jobcard where jc_id='".$myrow['id']."'";
		$result3=DB_query($query3,$db);
		$myrow3=DB_fetch_array($result3);
		if(empty($myrow3['servicesum'])) {echo "0";} else {echo $myrow3['servicesum'];}
		?>
	</td>
    <td><?php  echo $myrow['grandTotal']?></td>
	<td><?php  echo $myrow['pending_amount']?></td>
	<td><a href="<?php echo 'ACJobcardDetails.php?cnp='.$cnp.'&VPrefix='.$_REQUEST['VPrefix'].'&id='.$myrow['id']?>"> Receive Amount</a></td>
  </tr>
  <?php //}
  } }  ?>
</table>

