<?php
//***********************************VALIDATION FOR SEARCH****************START HERE*******************************/

if($_REQUEST['Search'])
{
	$fstatus=true;
	if($_REQUEST['site']=='0')
	{
	echo "<font color='#FF0000'>Please Select The Branch</font>";
	echo "<br/>";
	$fstatus=false;
	}
	if($_REQUEST['AccountName']=='0')
	{
	echo "<font color='#FF0000'>Please Select The Party</font>";
	echo "<br/>";
	$fstatus=false;
	}
	
}
//***********************************VALIDATION FOR SEARCH****************END HERE*******************************/


?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Accout Transaction Register</h1>
<div id="slidingDiv">
<form action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="3"> 
<tr class="row1">
	<td class="tabledata1">Branch</td>
	<td>
	<select name="site" id="site" style="width:150px;" >
	<option value="0">Select</option>
	<?php     
	$site_sql=DB_query("Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);
	while($site_row=DB_fetch_array($site_sql))
	{?>
	<option value="<?php echo $site_row['loccode']?>"<?php echo($_REQUEST['site']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname']?></option>
	<?php 	
	}
	?>
	</select></td>
	<td class="tabledata1">Account Name</td>
	<td><select name="AccountName" id="AccountName" style="width:150px;">
	<option value="0">Select Client</option>
	<?php
		  $ClientSQL="Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' and  Site in ('".$_SESSION['AssignedBranch']."')
		and Zone in(".$_SESSION['AssignedSites'].") order by c_name";
		$ClientRes=DB_query($ClientSQL,$db);
		while($ClientRow=DB_fetch_array($ClientRes)){?>
		<option value="<?php echo $ClientRow['id']?>" <?php echo ($_REQUEST['AccountName']==$ClientRow['id']?'selected':'');?>><?php echo $ClientRow['c_name']?></option>
		<?php  } ?>
	</select></td>
	</tr>
	<tr class="row1">
	<td class="tabledata1">From Date</td>
	<td><input name="frmDate" id="frmDate" type="text"  class="datepicker" style="width:150px;" value="<?php echo $_REQUEST['frmDate'];?>"/></td>
	<td class="tabledata1">To Date</td>
	<td><input name="ToDate" id="ToDate" type="text"  class="datepicker" style="width:150px;" value="<?php echo $_REQUEST['ToDate'];?>"  /></td>
	</tr>
<tr class="row1">
	<td colspan="4"><p align="center"><input type="submit" name="Search" value="Search" class="search" /></p></td>
</tr>
</table>
</form>
</div>
<?php 

//***********************************SEARCHING****************START HERE*****************************************/

if($_REQUEST['Search'] && $fstatus)
{
if($_REQUEST['site']!='0')	
{
$filter[]="mst_branchid ='".$_REQUEST['site']."'";
$search[]="branch='".$_REQUEST['site']."'";
$servicese[]="branch='".$_REQUEST['site']."'";
}
if($_REQUEST['AccountName']!='0')
{
$filter[]="company_name='".$_REQUEST['AccountName']."'";
$search[]="client='".$_REQUEST['AccountName']."'";
$servicese[]="party_name='".$_REQUEST['AccountName']."'";
}
if($_REQUEST['frmDate'] && $_REQUEST['ToDate']!='')
{
$frmdate=ConvertSQLDate($_REQUEST['frmDate']);
$filter[]="leads_date between '".ConvertSQLDate($_REQUEST['frmDate'])."' and '".ConvertSQLDate($_REQUEST['ToDate'])."' ";
$search[]="orderDate between '".ConvertSQLDate($_REQUEST['frmDate'])."' and '".ConvertSQLDate($_REQUEST['ToDate'])."'";
$servicese[]="job_card_date between '".ConvertSQLDate($_REQUEST['frmDate'])."' and '".ConvertSQLDate($_REQUEST['ToDate'])."'";
}
if($filter!='' && $search!='' && $servicese!='')
{
$filter=implode(" and ",$filter);
$search1=implode(" and ",$search);
$servicese1=implode(" and ",$servicese);
$mainSql="Select * from crm_leads where $filter and deleted_status='N'";//QUERY FOR PROCESS SALES ORDER
$SalesSql="Select * from salesorder where $search1";// QUERY FOR DIRECT SALES ORDER
$serviceSql="select * from trouble_ticket_jobcard where $servicese1";
}

//***********************************SEARCHING****************END HERE*****************************************/
?>



<p align="right"><a href="CRM/tcpdf/PDF_AccountTransReg.php"><input name="Exoprt" type="button" value="Export PDF" class="search" /></a></p>
<!--------------------------------CONTACT INFORMATION-----------------------START HERE---------------------------------->
<h3>Contact Information</h3>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
<tr class="row1">
<td class="tabledata">SNo.  </td>
<td class="tabledata">First Name  </td>
<td class="tabledata">Last Name</td>
<td class="tabledata">Company Name</td>
<td class="tabledata">Email</td>
<td class="tabledata">Office No </td>
<td class="tabledata">Mobile No</td>
<td class="tabledata">Country </td>
</tr>
<?php 
$i=1;
$ContactRes=DB_query($mainSql,$db);
while($ContactRow=DB_fetch_array($ContactRes))
{
?>	
<tr class="row1">
<td> <?php echo $i;?> </td>

<td> <?php echo $ContactRow['fname'];?> </td>
<td> <?php echo $ContactRow['lname'];?> </td>
<td><?php echo $s->GetFieldValue('clientmaster',"id='".$ContactRow['company_name']."'",'c_name');?>  </td>

<td><?php echo $ContactRow['email'];?>  </td>
<td> <?php echo $ContactRow['phone'];?> </td>
<td> <?php echo $ContactRow['mobile'];?> </td>
<td> <?php 
$CountrySql="select * from country_master where id='".$ContactRow['country']."'";
$CountryRes=DB_query($CountrySql,$db);
$CountryRow=DB_fetch_array($CountryRes);
echo $CountryRow['country'];
?></td>
</tr>
<?php
$i++;}?>
<?php

$i=1;
?>

</table>

<!--------------------------------CONTACT INFORMATION-----------------------END HERE------------------------------------->


<!--------------------------------LEAD INFORMATION-----------------------START HERE-------------------------------------->
<h3>Lead Information</h3>
<table width="100%" border="1" cellspacing="0" cellpadding="3">

<tr class="row1">
<td class="tabledata">SNo.</td>
<td class="tabledata">Lead No</td>
<td class="tabledata">Date</td>
<td class="tabledata">Lead Status  </td>
<td class="tabledata">Source</td>
<td class="tabledata">Company</td>
<td class="tabledata">Contact Person</td>
<td class="tabledata"> Status </td>
<td class="tabledata">Assigned To</td>
</tr>
<?php 



$mainRes=DB_query($mainSql,$db);
while($mainRow=DB_fetch_array($mainRes))
{
?>
<tr class="row1">
<td> <?php echo $i;?> </td>

<td> <?php echo $mainRow['leadcode'];?> </td>
<td> <?php echo ConvertSQLDate($mainRow['leads_date']);?> </td>
<td><?php echo $mainRow['lead_status'];?></td>
<td><?php echo $mainRow['lead_source'];?></td>
<td><?php echo $s->GetFieldValue('clientmaster',"id='".$mainRow['company_name']."'",'c_name');?></td>
<td> <?php echo $mainRow['contact_name'];?> </td>
<td> 
<?php if( $mainRow['Convert_IntoAccountStatus']=='Y')
{
echo "Convert Into Account";
}
else 
{
echo " Not Convert Into Account";	
}
?></td>
<td> <?php
$mainRow['leaduserid'];
$user=explode(',',$mainRow['leaduserid']);
$User1=implode("','",$user);


$Username="select userid from www_users where id IN('".$User1."')";
$UserSql=DB_query($Username,$db);
while($UserRow=DB_fetch_array($UserSql))
{
echo $UserRow['userid'].",";
}
?>	 </td>
</tr>
<?php
$i++;	
}
?>

</table>
<!--------------------------------LEAD INFORMATION-----------------------END HERE---------------------------------------->


<!--------------------------------FOLLOW UP INFORMATION-----------------------START HERE--------------------------------->
<h3>Follow up Information</h3>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
<tr class="row1">
<td class="tabledata">SNo.</td>
<td class="tabledata">Date</td>
<td class="tabledata">Lead No</td>
<td class="tabledata">Follow Up Type</td>
<td class="tabledata">Account Name</td>
<td class="tabledata" colspan="2">Follow Up Comments</td>
</tr>
<?php 
$mainSql;
$mainRes1=DB_query($mainSql,$db);
$mainRow1=DB_fetch_array($mainRes1);
$mainRow1['leadid'];

$FollowSql="Select * from crm_followup where mst_leadid='".$mainRow1['leadid']."'";
$FollowRes=DB_query($FollowSql,$db);
$i=1;
while($FollowRow=DB_fetch_array($FollowRes))
{?>
<tr class="row1">
<td> <?php echo $i;?> </td>
<td> <?php echo ConvertSQLDate($FollowRow['followDate']);?> </td>
<td><?php echo $mainRow1['leadcode'];?></td>
<td><?php echo $FollowRow['FollowType'];?></td>
<td><?php echo $s->GetFieldValue('clientmaster',"id='".$FollowRow['party']."'",'c_name');?></td>
<td> <?php echo $FollowRow['comments'];?> </td>
</tr>
<?php
$i++;	
}
?>

</table>
<!--------------------------------FOLLOW UP INFORMATION-----------------------END HERE------------------------------------>


<!--------------------------------EVENT INFORMATION-------------------------START HERE------------------------------------>
<h3>Events Information</h3>
<table width="100%" border="1" cellspacing="0" cellpadding="3">

<tr class="row1">
<td class="tabledata">SNo.</td>
<td class="tabledata">Event Type</td>
<td class="tabledata">Date</td>
<td class="tabledata">Event Desc</td>
<td class="tabledata">Lead No</td>
<td class="tabledata">Status</td>
<td class="tabledata">Priority</td>
<td class="tabledata">Start Timing</td>
<td class="tabledata">End Timing</td>
<td class="tabledata">Assigned User</td>
</tr>
<?php 

$EventSql1="Select * from crm_leadtodo where lead_type='Visit' and mst_leadid='".$mainRow1['leadid']."'";
$EventRes1=DB_query($EventSql1,$db);
$i=1;
while($EventRow1=DB_fetch_array($EventRes1))
{

?>
<tr class="row1">
<td> <?php echo $i;?> </td>
<td> <?php echo $EventRow1['lead_type'];?> </td>
<td> <?php echo ConvertSQLDate($EventRow1['tododatetime']);?> </td>
<td><?php echo $EventRow1['description'];?></td>
<td><?php echo $mainRow1['leadcode'];?></td>
<td><?php echo $EventRow1['todostatus'];?></td>
<td> <?php echo $EventRow1['lead_priority'];?> </td>
<td> <?php echo $EventRow1['todostart_time']."&nbsp; ".$EventRow1['tododue_date'];?> </td>
<td> <?php echo $EventRow1['todoend_time']." &nbsp;".$EventRow1['tododue_date'];?> </td>
<td> <?php
$user=explode(',',$EventRow1['leaduserid']);
$User1=implode("','",$user);
$Username="select * from www_users where id IN('".$User1."')";
$UserSql=DB_query($Username,$db);
while($UserRow=DB_fetch_array($UserSql))
{
echo  $UserRow['userid']." ";
} ?></td>
</tr>
<?php
$i++;	
}
?>

</table>
<!--------------------------------EVENT INFORMATION-----------------------END HERE-------------------------------------->


<!--------------------------------TO DO INFORMATION-----------------------START HERE-------------------------------------->
<h3>To Do Information</h3>
<table width="100%" border="1" cellspacing="0" cellpadding="3">

<tr class="row1">
<td class="tabledata">SNo.</td>
<td class="tabledata">Date</td>
<td class="tabledata">Subject</td>
<td class="tabledata">Task Desc</td>
<td class="tabledata">Priority</td>
<td class="tabledata">Lead No</td>
<td class="tabledata">Status</td>
<td class="tabledata">Assigned User</td>
</tr>
<?php 
$Lead_Todo=DB_query($mainSql,$db); 
while($TodoRow=DB_fetch_array($Lead_Todo))
{
$TaskSql="Select * from crm_leadtodo where lead_type='Task' and mst_leadid='".$TodoRow['leadid']."'";
$TaskRes=DB_query($TaskSql,$db);
$i=1;
while($TaskRow=DB_fetch_array($TaskRes))
{
?>
<tr class="row1">
<td><?php echo $i;?></td>
<td><?php echo ConvertSQLDate($TaskRow['tododatetime']);?></td>
<td><?php echo $TaskRow['leadtodo'];?></td>
<td><?php echo $TaskRow['description'];?></td>
<td><?php echo $TaskRow['lead_priority'];?></td>
<td><?php echo $TodoRow['leadcode'];?></td>
<td><?php echo $TaskRow['todostatus'];?></td>
<td><?php
$user=explode(',',$TaskRow['leaduserid']);
$User1=implode("','",$user);
$Username="select * from www_users where id IN('".$User1."')";
$UserSql=DB_query($Username,$db);
while($UserRow=DB_fetch_array($UserSql))
{
echo $UserRow['userid']." ,";
}?></td>
</tr>
<?php
$i++;	
}
}
$dir_todo=DB_query("select * from crm_add_to_do where client_id='".$_REQUEST['AccountName']."' and todo_date between '".ConvertSQLDate($_REQUEST['frmDate'])."' and '".ConvertSQLDate($_REQUEST['ToDate'])."'",$db);
while($dir_todo_Row=DB_fetch_array($dir_todo)){ ?>
<tr class="row1">
<td><?php echo $i;?></td>
<td><?php echo ConvertSQLDate($dir_todo_Row['todo_date']);?></td>
<td><a href="index.php?route=CRM/CrmfieldvisitreportTODO&action=View&todoid=<?php echo $dir_todo_Row['id'];?>&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>"><?php echo $dir_todo_Row['subject'];?></a></td>
<td><?php echo $dir_todo_Row['description'];?></td>
<td><?php echo $dir_todo_Row['priority'];?></td>
<td><?php echo "Direct";?></td>
<td><?php echo $dir_todo_Row['status'];?></td>
<td><?php
$user=explode(',',$dir_todo_Row['createdby']);
$User1=implode("','",$user);
$Username="select * from www_users where id IN('".$User1."')";
$UserSql=DB_query($Username,$db);
while($UserRow=DB_fetch_array($UserSql))
{
echo $UserRow['userid']." ,";
}?></td>
</tr>

<?php } ?>
</table>
<!--------------------------------TO DO INFORMATION-----------------------END HERE-------------------------------------->



<!--------------------------------SAMPLE INFORMATION-----------------------START HERE-------------------------------------->
<h3>Sample Information</h3>
<table width="100%" border="1" cellspacing="0" cellpadding="3">

<tr class="row1">
<td class="tabledata">Sample Date</td>
<td class="tabledata">Client</td>
<td class="tabledata">Executive Name</td>
<td class="tabledata">Shade Name</td>
<td class="tabledata">In Date</td>
<td class="tabledata">Out Date</td>

</tr>
<?php  $GetSample=DB_query("select * from crm_dot_request_form where site='".$_REQUEST['site']."' and client='".$_REQUEST['AccountName']."' and form_date between '".ConvertSQLDate($_REQUEST['frmDate'])."' and '".ConvertSQLDate($_REQUEST['ToDate'])."'",$db); 
while($SampleRow=DB_Fetch_array($GetSample)){?>
<tr class="row1">
<td><?php echo ConvertSQLDate($SampleRow['form_date']); ?></td>
<td><a href="index.php?route=CRM/dot_request_form&action=View&id=<?php echo $SampleRow['id']; ?>&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>"><?php echo $s->GetFieldValue('clientmaster',"id='".$SampleRow['client']."'",'c_name'); ?></a></td>
<td><?php echo $s->GetFieldValue('www_users',"id='".$SampleRow['executive']."'",'userid'); ?></td>
<td><?php echo $s->GetFieldValue('item_master',"id='".$SampleRow['shade_name']."'",'item_name'); ?></td>
<td><?php echo ConvertSQLDate($SampleRow['dot_in_date']); ?></td>
<td><?php echo ConvertSQLDate($SampleRow['dot_out_date']); ?></td>
</tr>
<?php } ?>


</table>
<!--------------------------------SAMPLE INFORMATION-----------------------END HERE-------------------------------------->



<!--------------------------------PANEL INFORMATION-----------------------START HERE-------------------------------------->
<h3>Panel Information</h3>

<table width="100%" border="1" cellspacing="0" cellpadding="3">

<tr class="row1">
<td class="tabledata">Vouchar No.</td>
<td class="tabledata">Date</td>
<td class="tabledata">Shade Name</td>
<td class="tabledata">In Date</td>
<td class="tabledata">Out Date</td>
<td class="tabledata">Executive</td>
<td class="tabledata">Remarks</td>

</tr>
<?php  $GetPanel=DB_query("select * from crm_panel_entry where site='".$_REQUEST['site']."' and client='".$_REQUEST['AccountName']."' and panel_date between '".ConvertSQLDate($_REQUEST['frmDate'])."' and '".ConvertSQLDate($_REQUEST['ToDate'])."'",$db); 
while($PanelRow=DB_Fetch_array($GetPanel)){?>
<tr class="row1">
<td><a href="index.php?route=CRM/panel_entry&action=View&id=<?php echo $PanelRow['id']; ?>&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>"><?php echo $PanelRow['vouchar_no']; ?></a></td>
<td><?php echo ConvertSQLDate($PanelRow['panel_date']); ?></td>
<td><?php echo $s->GetFieldValue('item_master',"id='".$PanelRow['shade_name']."'",'item_name'); ?></td>
<td><?php echo ConvertSQLDate($PanelRow['panel_in_date']); ?></td>
<td><?php echo ConvertSQLDate($PanelRow['panel_out_date']); ?></td>
<td><?php echo $s->GetFieldValue('www_users',"id='".$PanelRow['executive']."'",'userid'); ?></td>
<td><?php echo $PanelRow['remark']; ?></td>
</tr>
<?php } ?>

</table>
<!--------------------------------PANEL INFORMATION-----------------------END HERE-------------------------------------->







<!--------------------------------QUOTES INFORMATION-----------------------START HERE------------------------------------>
<h3>Quotes Information</h3>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
<tr class="row1">
<td class="tabledata">SNo.</td>
<td class="tabledata">Date</td>
<td class="tabledata">Quote No</td>
<td class="tabledata">Against Lead</td>
<td class="tabledata">Valid Till</td>
<td class="tabledata" colspan="2">Status</td>
<td class="tabledata" colspan="2">Assigned User</td>
<td class="tabledata">Total Quote Amt</td>

</tr>
<?php 
$QuotesSql="Select * from quotation where enquiryNo='".$mainRow1['leadid']."'";
$QuotesRes=DB_query($QuotesSql,$db);
$i=1;
while($QuotesRow=DB_fetch_array($QuotesRes))
{

?>
<tr class="row1">
<td> <?php echo $i;?> </td>
<td><?php echo ConvertSQLDate($QuotesRow['quotationDate']);?></td>
<td> <?php echo $QuotesRow['quotationNo'];?> </td>
<td><?php echo $mainRow1['leadcode'];?></td>
<td><?php echo ConvertSQLDate($QuotesRow['validTill']);?></td>
<td colspan="2"> <?php
if($QuotesRow['ConvertIntoSales']=='Y')
{
echo "Convert To Sales";

}
else
{
echo " Not Convert To Sales";
}
?> </td>
<td colspan="2"> <?php 
$user=explode(',',$mainRow1['leaduserid']);
$User1=implode("','",$user);
$Username="select * from www_users where id IN('".$User1."')";
$UserSql=DB_query($Username,$db);
while($UserRow=DB_fetch_array($UserSql))
{
echo $UserRow['userid']," ,";
}
?> </td>
<td> <?php echo $QuotesRow['grandTotal'];?> </td>
</tr>
<?php
$i++;	
}

?>

</table>
<!--------------------------------QUOTES INFORMATION-----------------------END HERE------------------------------------>


<!--------------------------------SALES ORDER INFORMATION-----------------------START HERE-------------------------------->
<h3>Sales Order Information:</h3>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
<tr class="row1">
<td class="tabledata">SNo.</td>
<td class="tabledata" colspan="2">Sale Order No</td>
<td class="tabledata">Date</td>
<td class="tabledata">Against Quote</td>
<td class="tabledata">PO Ref No</td>
<!--<td class="tabledata">Valid Till</td>-->
<td class="tabledata">Order Type</td>
<td class="tabledata">Total Order Qty</td>
<td class="tabledata">Total Order Amt</td>
<td class="tabledata">Status</td>
</tr>
<?php 
//$QuotesSql="Select * from quotation where enquiryNo='".$mainRow1['leadid']."'";
//$QuotesRes=DB_query($QuotesSql,$db);
//$QuotesRow=DB_fetch_array($QuotesRes);
//
//echo $QuotesRow['SalesOrderNo'];
//
//$order_type=DB_query($SalesSql,$db);
//
//$order_typeRow=DB_fetch_array($order_type);
//$order_typeRow['SalesOrderType'];
//if($order_typeRow['SalesOrderType']=='Process' || $order_typeRow['SalesOrderType']=='Tel')
//{
//echo $SalesSql="Select * from salesorder where id='".$QuotesRow['SalesOrderNo']."' or $search1";
//}
$SalesRes=DB_query($SalesSql,$db);
$i=1;
while($SalesRow=DB_fetch_array($SalesRes))
{
$QTYSQL=DB_Query("select SUM(Quantity) TOTALQTY from salesorder_details where masterId='".$SalesRow['id']."'",$db);
$FINALQTY=DB_fetch_array($QTYSQL);
?>
<tr class="row1">
<td> <?php echo $i;?> </td>
<td colspan="2"><a href="index.php?route=CRM/TelephonicView&action=View&SOrderId=<?php echo $SalesRow['id'] ?>&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>"> <?php echo $SalesRow['orderNo'];?></a> </td>
<td><?php echo ConvertSQLDate($SalesRow['orderDate']);?></td>
<td><?php if($SalesRow['SalesOrderType']=='Process'){echo "Process";}else{echo "Direct";}?></td>
<td><?php echo $SalesRow['PORefNo'];?></td>
<!--<td> <?php echo $SalesRow['validTill'];?> </td>-->
<td> <?php echo $SalesRow['order_type'];?> </td>
<td><?php echo $FINALQTY['TOTALQTY'];?></td>
<td><?php echo $SalesRow['grandTotal'];?></td>
<td> <?php echo $SalesRow['status'];?></td>
</tr>
<?php
$i++;	
}
?>

</table>
<!--------------------------------SALES ORDER INFORMATION-----------------------END HERE-------------------------------->


<!--------------------------------DISPATCH ADVOICE NOTE-----------------------START HERE-------------------------------->
<h3>Dispatch Advice Note</h3>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
<tr class="row1">
<td class="tabledata">SNo.</td>
<td class="tabledata" colspan="2">Dispatch Advice No</td>
<td class="tabledata">Date</td>
<td class="tabledata">Against SOP</td>
<td class="tabledata">Total Order Qty</td>
<td class="tabledata">Dispatch Qty</td>
<td class="tabledata">Pending Qty</td>
<td class="tabledata">Total Ammount</td>
<td class="tabledata">Status</td>
</tr>
<?php 
 $DispatchSql="Select * from dispatch where party='".$_REQUEST['AccountName']."' and createdDate between '".ConvertSQLDate($_REQUEST['frmDate'])."' and '".ConvertSQLDate($_REQUEST['ToDate'])."'";
$DispatchRes=DB_query($DispatchSql,$db);
//$QuotesRow=DB_fetch_array($QuotesRes);
// $SalesSql="Select * from salesorder where id='".$QuotesRow['againstSOP']."'";
//$SalesRes=DB_query($SalesSql,$db);
$i=1;
while($SalesRow=DB_fetch_array($DispatchRes))
{
?>
<tr class="row1">
<td> <?php echo $i;?> </td>
<td colspan="2"><a href="index.php?route=CRM/dispatch_list&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=view&Id=<?php echo $SalesRow['againstSOP']; ?>"><?php echo $SalesRow['adviceNo'];?></a></td>
<td><?php echo ConvertSQLDate($SalesRow['dispatchDate']);?></td>
<td><?php echo $s->GetFieldValue('salesorder',"id='".$SalesRow['againstSOP']."'",'orderNo');?></td>
<td><?php
$Total_oq=DB_query("SELECT SUM(orderQty) as TOTALQTY FROM dispatch_details WHERE SOPNo='".$SalesRow['againstSOP']."'",$db);
$Total_oqRow=DB_fetch_array($Total_oq);
echo $Total_oqRow['TOTALQTY'];
?></td>
<td> <?php echo $SalesRow['totalDispatch'];?> </td>
<td> <?php 
$Pend_Qty=DB_query("SELECT SUM(pendingQty) AS PENDING_QTY from salesorder_details where masterId='".$SalesRow['againstSOP']."'",$db);
$Pend_QtyRow=DB_fetch_array($Pend_Qty);
echo $Pend_QtyRow['PENDING_QTY'];?> </td>
<td><?php echo $SalesRow['grandTotal'];?></td>
<td> <?php echo $SalesRow['status'];?></td>
</tr>
<?php
$i++;	
}

?>

</table>
<!--------------------------------DIAPATCH ADVOICE NOTE-----------------------END HERE-------------------------------->


<!--------------------------------INVOICE INFORMATION-----------------------START HERE-------------------------------->
<h3>Invoice </h3>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
<tr class="row1">
<td class="tabledata">SNo.</td>
<td class="tabledata" colspan="2">Invoice No</td>
<td class="tabledata">Invoice Date</td>
<td class="tabledata">Against D.A.</td>
<td class="tabledata">Item Qty</td>
<td class="tabledata">Basic Amt</td>
<td class="tabledata">Discounted Amt</td>
<td class="tabledata">Excise Amt</td>
<td class="tabledata">Tax Amt</td>
<td class="tabledata">Total Inv Amt</td>
</tr>

<?php 
$QuotesSql="Select * from invoice where client_id='".$_REQUEST['AccountName']."'";
$SalesRes=DB_query($QuotesSql,$db);
$i=1;
while($SalesRow=DB_fetch_array($SalesRes))
{

?>
<tr class="row1"> 
<td> <?php echo $i;?> </td>
<td colspan="2"> <?php echo $SalesRow['invoiceNo'];?> </td>
<td><?php echo ConvertSQLDate($SalesRow['invoiceDate']);?></td>
<td><?php   echo $SalesRow['dispatchNo']; ?></td>
<td><?php
$QuotesSql1="Select count(Quantity) as amt from invoice_details where invoiceid='".$SalesRow['invoice_id']."'";
$QuotesRes1=DB_query($QuotesSql1,$db);
$QuotesRow1=DB_fetch_array($QuotesRes1);
echo $QuotesRow1['amt'];?></td>

</td>
<td> <?php echo $SalesRow['basicAmount'];?> </td>
<td> <?php echo $SalesRow['totalDiscountedPrice'];?> </td>
<td><?php echo $SalesRow['ECessValue']+$SalesRow['SAHCessValue']+$SalesRow['exciseValue'];?></td>
<td> <?php echo $SalesRow['VatCstValue'];?></td>
<td><?php echo $SalesRow['grandTotal'];?></td>
</tr>
<?php
$i++;	
}

?>
</table>
<!--------------------------------INVOICE INFORMATION-----------------------END HERE-------------------------------->





<!--------------------------------DAILY VISIT REPORT INFORMATION-----------------------START HERE-------------------------------->
<h3>Daily Visit Report </h3>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
<tr class="row1">
<td class="tabledata">SNo.</td>
<td class="tabledata" colspan="2">Date</td>
<td class="tabledata">Contact Person</td>
<td class="tabledata">Remark</td>
<td class="tabledata">Comment</td>
<td class="tabledata">Executive</td>
</tr>

<?php  $DailySQL="Select * from crm_daily_visit_entry where client_id='".$_REQUEST['AccountName']."'";
$DailyReport=DB_query($DailySQL,$db);
$i=1;
while($DailyRow=DB_fetch_array($DailyReport))
{
?>
<tr class="row1">
<td> <?php echo $i;?> </td>
<td colspan="2"> <?php echo ConvertSQLDate($DailyRow['visit_date']);?> </td>
<td><a href="index.php?route=CRM/ViewDailyEntry&action=View&VisitId=<?php echo $DailyRow['mst_crm_entryid']; ?>&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>"><?php echo $DailyRow['ClientContact'];?></a></td>
<td><?php echo $DailyRow['remark']; ?></td>
<td><?php echo $DailyRow['comment']; ?></td>
<td><?php  $User_id=$s->GetFieldValue('crm_mst_daily_visit_entry',"id='".$DailyRow['mst_crm_entryid']."'",'empid');
echo $s->GetFieldValue('www_users',"id='".$User_id."'",'userid');
?></td>
</td>
</tr>
<?php
$i++;	
}
?>
</table>
<!--------------------------------DAILY VISIT REPORT INFORMATION-----------------------END HERE-------------------------------->



<!--------------------------------DAILY VISIT REPORT INFORMATION-----------------------START HERE-------------------------------->

<!--<h3>Service Report</h3>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
<tr class="row1">
<td class="tabledata">SNo.</td>
<td class="tabledata">TT No.</td>
<td class="tabledata">JC No.</td>
<td class="tabledata">Product Name</td>
<td class="tabledata">Fault Desc</td>
<td class="tabledata">Current Status</td>
<td class="tabledata">Service Amt.</td>
</tr>

<?php 
$SQLSer=DB_query($serviceSql,$db);
$i=0; while($serviceRow=DB_fetch_array($SQLSer)) {?>
<tr class="row1">
<td><?php echo $i+1; ?></td>
<td><?php echo $s->GetFieldValue('trouble_ticket_creation',"id='".$serviceRow['ticket_number']."'",'ticket_number'); ?></td>
<td><?php echo $serviceRow['job_card_number'] ?></td>
<td><?php echo $s->GetFieldValue('item_master',"id='".$serviceRow['product_name']."'",'item_name') ?></td>
<td><?php echo $serviceRow['prob_desc'] ?></td>
<td><?php if($serviceRow['status']==1){echo 'Open';}
if($serviceRow['status']==2){echo 'In Process';}
if($serviceRow['status']==3){echo 'Close';} ?></td>
<td><?php echo $serviceRow['serviceAmount'] ?></td>
</tr>
<?php $i++;} ?>
</table>-->
<!--------------------------------DAILY VISIT REPORT INFORMATION-----------------------START HERE-------------------------------->




<?php  }?>



</div></div>