<?php 
//include('functions.php');
//include('functionsgetdep.php');
include('includes/Class_Client.php');
//include('Class_PickListEditor.php');
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<script>
function displatPeriod()
{
	if(document.getElementById("getperiod").style.display!='block')
	{
	document.getElementById("getperiod").style.display="block";
	document.getElementById("getparty").style.display="none";
	document.getElementById("gettech").style.display="none";
	document.getElementById("pty").style.display="none";
	document.getElementById("tec").style.display="none";
	}
}


function displatParty()
{
	if(document.getElementById("getparty").style.display!='block')
	{
	document.getElementById("getparty").style.display="block";
	document.getElementById("getperiod").style.display="none";
	document.getElementById("gettech").style.display="none";
	document.getElementById("pr").style.display="none";
	document.getElementById("tec").style.display="none";
	}
}

function periodval()
{
	if(document.getElementById("site").value=='0')
	{
		alert("Please select Branch Name.");
		return false;
	}
	if(document.getElementById("fromdate").value=='')
	{
		alert("Please Enter From Date.");
		return false;
	}
	if(document.getElementById("todate").value=='')
	{
		alert("Please Enter To Date.");
		return false;
	}
	return true;
}
function partyval()
{
	if(document.getElementById("site1").value=='0')
	{
		alert("Please select Branch Name.");
		return false;
	}
	if(document.getElementById("client").value=='')
	{
		alert("Please Select Party Name.");
		return false;
	}
	return true;
}
</script>
<?php 
//**********************************PERIOD WISE SEARCHING******10-11-2012*************START HERE************************/
if($_REQUEST['SearchPeriod']=='Search')
{
	$fromdate=FormatDateForSQL($_REQUEST['fromdate']);
	$todate=FormatDateForSQL($_REQUEST['todate']);
	if(strlen($fromdate)==10 && strlen($todate)==10)
	{
	$filter[]="job_card_date between '".$fromdate."' and '".$todate."'";
	}
	if($_REQUEST['site']!='0')
	{
	$filter[]="Branch = '".$_REQUEST['site']."'";
	}
	if($filter!='')
	{
	$filter1=implode(" and ",$filter);
	$sql = "select * from  trouble_ticket_jobcard where $filter1";
	$GetPeriodData= DB_query($sql,$db);
	}
	else
	{
	$sql = "select * from  trouble_ticket_jobcard";
	$GetPeriodData= DB_query($sql,$db);
	}
}
//**********************************PERIOD WISE SEARCHING*******************END HERE******************************************/




//**********************************Party WISE SEARCHING*******************START HERE*************************************/

if($_REQUEST['SearchParty'])
{
	$fDate=FormatDateForSQL($_REQUEST['fDate']);
	$tDate=FormatDateForSQL($_REQUEST['tDate']);
	if(strlen($fDate)==10 && strlen($tDate)==10)
	{
	$filter3[]= "job_card_date BETWEEN '".$fDate."' and '".$tDate."'";
	}
	if($_REQUEST['site']!='0')
	{
	$filter3[]="Branch='".$_REQUEST['site']."'";
	}
	if($_REQUEST['client']!='')
	{
	$filter3[]="party_name = '".$_REQUEST['client']."'";
	}
		if($filter3!='')
	{
	$Fil = implode(" and ",$filter3);
	$sql = "select * from  trouble_ticket_jobcard where $Fil";
	$GetParty = DB_query($sql,$db);
	}
	else
	{
	$sql = "select * from  trouble_ticket_jobcard";
	$GetParty = DB_query($sql,$db);
	}

}
//**********************************Party WISE SEARCHING*******************END HERE*************************************/
?>
<div class="body_contain">
<div class="tab_div">
<h1>Payment Collection   Register </h1>
<?php //print_r($_REQUEST); ?>
<!--<input name="radiobutton" type="radio" value="technician" onclick="displatPeriod('getperiod')" />
    Period Wise
    <input name="radiobutton" type="radio" value="assignment" onclick="displatParty('getparty')"/>
    Party Wise
    <input name="radiobutton" type="radio" value="register" onclick="displatech('gettech')"/>
    Technician Wise <br />-->
<input name="period" type="radio" value="period" <?php if($_REQUEST['SearchPeriod']=='Search'){ echo 'checked' ;}else{ }?> onclick="displatPeriod(this.value)"/>
Period Wise
<input name="period" type="radio" value="party" <?php if($_REQUEST['SearchParty']=='Search'){ echo 'checked' ;}else{ }?> onclick="displatParty(this.value)"/>
Party Wise
<!--<input name="period" type="radio" value="tech" <?php if($_REQUEST['SearchTech']=='Search'){ echo 'checked' ;}else{ }?> onclick="displatech(this.value)"/>
Technician Wise --><br />
<br />
<div style="display:none" id="getperiod">
<form action="" method="post">
<table width="100%" border="0" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
	<tr>
        <td nowrap="nowrap" scope="row">Branch</td>
        <td nowrap="nowrap"><select name="site" id="site"  style="width:150px;">
            <option value="0">--All--</option>
            <?php $Sitesql="select * from locations where  CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
					$SiteRes=DB_query($Sitesql,$db);
					while($SiteRow=DB_fetch_array($SiteRes)){?>
            <option value="<?php  echo $SiteRow['loccode'];?>" <?php  echo $_REQUEST['site']==$SiteRow['loccode']?'selected':''?> >
            <?php  echo $SiteRow['locationname'];?>
            </option>
            <?php } ?>
          </select>
        </td>
        <td nowrap="nowrap" scope="row">From Date</td>
        <td nowrap="nowrap"><input name="fromdate" id="fromdate" type="text"  class="datepicker" style="width:150px;" value="<?php echo $_REQUEST['fromdate'];?>" /></td>
        <td nowrap="nowrap" scope="row">To Date</td>
        <td nowrap="nowrap"><input name="todate" id="todate" type="text"  class="datepicker" style="width:150px;"  value="<?php echo $_REQUEST['todate'];?>" /></td>
		<td><input type="submit" name="SearchPeriod" value="Search" class="bottonsview" onclick="return periodval()"/></td>
      </tr>
    </table>
  </form>
</div>
<div style="display:none" id="getparty">
<form action="" method="post">
<table width="100%" border="0" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
      <tr>
        <td nowrap="nowrap" scope="row">Branch</td>
        <td width="13%" nowrap="nowrap"><select name="site" id="site1"  style="width:100%;">
            <option value="0">--All--</option>
            <?php
					$Sitesql="select * from locations where  CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
					$SiteRes=DB_query($Sitesql,$db);
					while($SiteRow=DB_fetch_array($SiteRes))
					{?>
            <option value="<?php  echo $SiteRow['loccode'];?>" <?php  echo $_REQUEST['site']==$SiteRow['loccode']?'selected':''?> >
            <?php  echo $SiteRow['locationname'];?>
            </option>
            <?php } ?>
          </select>
        </td>
        <td nowrap="nowrap" scope="row">Party</td>
        <td nowrap="nowrap"><select name="client" id="client" style="width:150px;" >
            <option value="">--All--</option>
            <?php
					$Client="select * from clientmaster";
					$ClientRes=DB_query($Client,$db);
					while($ClientResRow=DB_fetch_array($ClientRes))
					{
					$sel='';
					if($_REQUEST['client']==$ClientResRow['id'])
					$sel='selected';?>
            <option value="<?php  echo $ClientResRow['id'];?>" <?php echo $sel; ?>>
            <?php  echo $ClientResRow['c_name'];?>
            </option>
            <?php } ?>
          </select>
          <?php echo $ClientSQL= $s->GetFieldValue('clientmaster', 'id="'.$fetch_tt_qry['part_name'].'"','c_name');?></td>
        <td nowrap="nowrap" scope="row">From Date</td>
        <td nowrap="nowrap"><input name="fDate" id="fDate" type="text"  class="datepicker" style="width:150px;"  value="<?php echo $_REQUEST['fDate'];?>" /></td>
        <td nowrap="nowrap" scope="row">To Date</td>
        <td nowrap="nowrap"><input name="tDate" id="tDate" type="text"  class="datepicker" style="width:150px;"   value="<?php echo $_REQUEST['tDate'];?>" /></td>
		<td><input type="submit" name="SearchParty" value="Search" class="bottonsview" onclick="return partyval()" /></td>
      </tr>
    </table>
  </form>
</div>
<!-----------------------------PERIOD WISE REPORT---------------START HERE----------------------------------------------->
</p>
<?php if($_REQUEST['SearchPeriod']){?>
<script>document.getElementById("getperiod").style.display="block";</script>
<div id="pr">
<table width="100%" border="1" cellpadding="0" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
<tr>
      <td colspan="12" class="tabledata"><strong>Showing Payment Collection Register From <?php echo $_REQUEST['fromdate']; ?> To <?php echo $_REQUEST['todate']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $s->GetFieldValue('locations',"loccode='".$_REQUEST['site']."'",'locationname'); ?></strong></td>
</tr>
<tr>
      <td class="tabledata"><strong>S. No.</strong></td>
      <td class="tabledata"><strong>JC No.</strong></td>
	  <td class="tabledata"><strong>JC opennig Date</strong></td>
      <td class="tabledata"><strong>JC closed Date</strong></td>
      <td class="tabledata"><strong>JC Status</strong></td>
	  <td class="tabledata"><strong>Party Name</strong></td>
	  <td class="tabledata"><strong>Spare Part Amt.</strong></td>
	  <td class="tabledata"><strong>Service Amt.</strong></td>
	  <td class="tabledata"><strong>Total Amt.</strong></td>
	  <td class="tabledata"><strong>Received Date</strong></td>
      <td class="tabledata"><strong>Payment Type</strong></td>
	  <td class="tabledata"><strong>Recv. Amt.</strong></td>
</tr>
    <?php 
	if(DB_num_rows($GetPeriodData)>0){
			$i=1;
			while($fetchData1 = DB_fetch_array($GetPeriodData)){
		?>
<tr>
      <td class="tabledata"><?php echo $i;?></td>
      <td class="tabledata"><?php echo $fetchData1['job_card_number'];?></td>
      <td class="tabledata"><?php echo ConvertSQLDate($fetchData1['job_card_date']);?></td>
	  <td class="tabledata"><?php echo ConvertSQLDate($fetchData1['jc_closedate']);?></td>
      <td class="tabledata"><?php if($fetchData1['status']==1){echo 'Open';}
	  							  if($fetchData1['status']==2){echo 'In process';}
								  if($fetchData1['status']==3){echo 'Close';}?></td>
	   <td class="tabledata"><?php echo $s->GetFieldValue('clientmaster', 'id="'.$fetchData1['party_name'].'"','c_name');?></td>
	  <td class="tabledata"><?php echo $serviceAmt=$s->GetFieldValue('add_service_jobcard',"jc_id='".$fetchData1['id']."'",'sum(service_amt)');?></td>
	  <td class="tabledata"><?php echo $spareAmt=$s->GetFieldValue('trouble_ticket_jobcard_details',"jc_id='".$fetchData1['id']."'",'sum(amt)');?></td>
      <td class="tabledata"><?php echo $fetchData1['grandTotal'];?></td>
	  <td class="tabledata" colspan="3"><table border="0" cellpadding="0" cellspacing="0" width="100%" style="border:none;">
	  <?php $SQLS=DB_query("SELECT adjustment, account_book_id, posted_date FROM account_service_billbook where service_billbookid='".$fetchData1['id']."' and status='1'",$db);
	  if(DB_num_rows($SQLS)>0){
	  		$rec_tot=0;
			while($SQLSRow=DB_fetch_array($SQLS)){
	  ?>		
<tr>
			<td class="tabledata" style="width:80px;"><?php echo $SQLSRow['posted_date'];?></td>
			<td class="tabledata" style="width:70px;"><?php $pay_type=$s->GetFieldValue('account_book', 'id="'.$SQLSRow['account_book_id'].'"', 'transation_type'); if($pay_type==''){echo "Cash";}else{echo $pay_type;}?></td>
	  		<td class="tabledata"><?php echo $SQLSRow['adjustment']; $rec_tot += $SQLSRow['adjustment'];?></td>
			
			
</tr>
	  <?php } ?>
	  <tr>
	  <td class="tabledata">&nbsp;</td>
	   <td class="tabledata"><strong>Total</strong></td>
	   <td class="tabledata"><strong><?php echo $rec_tot; ?></strong></td>
</tr>
	  <?php } ?>
	  </table>
	  </td>
    </tr>
    <?php $i++;}  } else {?>
		<tr>
			<td colspan="12" style="color:#FF0000;">No Record Found</td>
		</tr>
		<?php } ?>
  </table>
</div>
<br />
<?php }else{?>
<script>document.getElementById("getperiod").style.display="none";</script>
<?php }?>
<!-----------------------------PERIOD WISE REPORT---------------END HERE-------------------------------------------------->



<!-----------------------------PARTY WISE REPORT---------------START HERE------------------------------------------------->
<?php if($_REQUEST['SearchParty']){?>
<script>document.getElementById("getparty").style.display="block";</script>
<div id="pty">
  <table width="100%" border="1" cellpadding="0" cellspacing="0" style="border-collapse:collapse;">
    <tr>
      <td colspan="11" class="tabledata"><strong>Showing Payment Collection Register For <?php echo $s->GetFieldValue('clientmaster',"id='".$_REQUEST['client']."'",'c_name'); ?>&nbsp;&nbsp;From <?php echo $_REQUEST['fDate']; ?> To <?php echo $_REQUEST['tDate']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $s->GetFieldValue('locations',"loccode='".$_REQUEST['site']."'",'locationname'); ?></strong></td>
    </tr>
    <tr>
      <td class="tabledata"><strong>S. No.</strong></td>
      <td class="tabledata"><strong>JC No.</strong></td>
	  <td class="tabledata"><strong>JC opennig Date</strong></td>
      <td class="tabledata"><strong>JC closed Date</strong></td>
      <td class="tabledata"><strong>JC Status</strong></td>
	  <td class="tabledata"><strong>Spare Part Amt</strong></td>
	  <td class="tabledata"><strong>Service Amt.</strong></td>
	  <td class="tabledata"><strong>Total Amt.</strong></td>
      <td class="tabledata"><strong>Received Date</strong></td>
      <td class="tabledata"><strong>Payment Type</strong></td>
	  <td class="tabledata"><strong>Recv. Amt.</strong></td>
    </tr>
    <?php
	if(DB_num_Rows($GetParty)>0){
	 $i=0;
while($fetchParty=DB_fetch_array($GetParty)){
$serviceAmt=$s->GetFieldValue('add_service_jobcard',"jc_id='".$fetchParty['PID']."'",'sum(service_amt)');
		?>
    <tr>
      <td class="tabledata"><?php echo $i+1;?></td>
      <td class="tabledata"><?php echo $fetchParty['job_card_number'];?></td>
      <td class="tabledata"><?php echo ConvertSQLDate($fetchParty['job_card_date']);?></td>
      <td class="tabledata"><?php echo ConvertSQLDate($fetchParty['closing_date']);?></td>
      <td class="tabledata"><?php if($fetchParty['status']==1){echo 'Open';}
	  							  if($fetchParty['status']==2){echo 'In process';}
								  if($fetchParty['status']==3){echo 'Close';}?></td>
      <td class="tabledata"><?php echo $serviceAmt=$s->GetFieldValue('add_service_jobcard',"jc_id='".$fetchParty['id']."'",'sum(service_amt)');?></td>
       <td class="tabledata"><?php echo $spareAmt=$s->GetFieldValue('trouble_ticket_jobcard_details',"jc_id='".$fetchParty['id']."'",'sum(amt)');?></td>
      <td class="tabledata"><?php echo $fetchParty['grandTotal'];?></td>
	<td class="tabledata" colspan="3"><table border="0" cellpadding="0" cellspacing="0" width="100%" style="border:none;">
	  <?php $SQLS=DB_query("SELECT adjustment, account_book_id, posted_date FROM account_service_billbook where service_billbookid='".$fetchParty['id']."' and status='1'",$db);
	  if(DB_num_rows($SQLS)>0){
	  		$rec_tot=0;
			while($SQLSRow=DB_fetch_array($SQLS)){
	  ?>		
	  	<tr>
			<td class="tabledata" style="width:100px;"><?php echo $SQLSRow['posted_date'];?></td>
			<td class="tabledata" style="width:90px;"><?php $pay_type=$s->GetFieldValue('account_book', 'id="'.$SQLSRow['account_book_id'].'"', 'transation_type'); if($pay_type==''){echo "Cash";}else{echo $pay_type;}?></td>
	  		<td class="tabledata"><?php echo $SQLSRow['adjustment']; $rec_tot += $SQLSRow['adjustment'];?></td>
			
			
	  	</tr>
	  <?php } ?>
	  <tr>
	  <td class="tabledata">&nbsp;</td>
	   <td class="tabledata"><strong>Total</strong></td>
	   <td class="tabledata"><strong><?php echo $rec_tot; ?></strong></td>
	  </tr>
	  <?php } ?>
	  </table></td>				  
    </tr>
    <?php $i++;
		} }else {?>
		<tr>
		<td colspan="11" style=" color:#FF0000;">No Record Found</td>
		</tr>
		<?php } ?>
  </table>
</div>
<br />
<?php }else{?>
<script>document.getElementById("getparty").style.display="none";</script>
<!-----------------------------PARTY WISE REPORT---------------END HERE---------------------------------------------------->
<?php }?>



