<script language="javascript" type="text/javascript">
function showsitename160(str)
{

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	var data=xmlhttp.responseText.split("__");	
	document.getElementById("storedata7").innerHTML=data[0];
	  }
  }
  xmlhttp.open("GET","get_dealerclient.php?site="+str,true);
	xmlhttp.send();
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Pick List Reports</h1>
<form method="post" action="">
<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td width="18%" class="tabledata1">Dealer</td>
    <td width="29%">
			<?php
	if(!empty($_SESSION['dealerid']))
	  {	  	
  $ss1="Select * from dbl_dealer where company='".$_SESSION['ACGCompanyId']."' 
   and id='".$_SESSION['dealerid']."'";
 $site_sql1=DB_query($ss1,$db);
     }
  else
    {
	$ss1="Select * from dbl_dealer where company='".$_SESSION['ACGCompanyId']."'";
	$site_sql1=DB_query($ss1,$db);
	}
	?>
<select name="dealer" id="dealer" onchange="showsitename160(this.value)" style="width:150px;">
<option value="">Select Site</option>
<?php 
while($site_row = DB_fetch_array($site_sql1))
{
$p='';
if($site_row['id'] == $_POST['dealer'])	
$p="selected";
?>
<option value="<?php echo $site_row['id']; ?>" <?php echo $p;?>><?php echo $site_row['dealer_name']; ?></option>
<?php } ?>
</select></td>
	<td width="18%" class="tabledata1">Customer</td>
    <td width="35%"><div id="storedata7">
        <?php 
	   $store_sql = "SELECT * FROM clientmaster where CompanyId = '".$_SESSION['ACGCompanyId']."'";
	   $store_result = DB_query($store_sql,$db);  	  
	  ?>
      <select name="customer" id="customer" style="width:150px;">
	  <option value="0">Select</option>
      <?php
	  while($store_row = DB_fetch_array($store_result))
			{
			
	  ?>
 <option value="<?php echo $store_row['id'];?>"<?php echo($_REQUEST['customer']==$store_row['id']?'selected':'')?>><?php echo $store_row['c_name'];?></option>
                  <?php }?>
              </select>
          </div></td>
</tr>




<tr class="row1">
	<td class="tabledata1">From</td>
    <td><input type="text" name="from_date" style="width:150px;" value="<?php echo $_POST['from_date'];?>" class="datepicker"></td>
	<td class="tabledata1">To</td>
    <td><input type="text" name="to_date" style="width:150px;" value="<?php echo $_POST['to_date'];?>" class="datepicker"></td>
</tr>
<tr class="row1">
	<td class="tabledata1">PickList Type</td>
    <td><select name="picklisttype" id="picklisttype" style="width:150px;">
	    <option value="">Select</option>
		<option value="With Invoice">With Invoice</option>
		<option value="Without Invoice">Without Invoice</option>
		</select>	</td>
	<td colspan="2" class="tabledata1"></td>
	</tr>


<tr class="row1">
	<td class="tabledata1" style="text-align:center;" colspan="4">
	<input type="submit" name="view" class="search" value="View">	</td>
</tr>
</table>
		

</form>
<?php 
if($_REQUEST['view']!='')
{
	$fromdate=$_REQUEST['from_date'];
	$todate=$_REQUEST['to_date'];
	$fromdate_brk=explode('/',$fromdate);
	$from=$fromdate_brk[2]."-".$fromdate_brk[1]."-".$fromdate_brk[0];
	$todate_brk=explode('/',$todate);
	$to=$todate_brk[2]."-".$todate_brk[1]."-".$todate_brk[0];
	$sitename=$s->getField('dbl_dealer','id',$_REQUEST['dealer'],'dealer_name');
	$filter=array();
	if($_REQUEST['dealer']!='')
	$filter[]="dbl_dealer_dispatch.dealer = '".$_REQUEST['dealer']."'";
	if($_REQUEST['customer']!='0')
	$filter[]="dbl_dealer_dispatch.customer = '".$_REQUEST['customer']."'";
	if($_REQUEST['picklisttype']!='')
	$filter[]="dbl_dealer_dispatch.pick_list_type = '".$_REQUEST['picklisttype']."'";
	if($_REQUEST['from_date']!='' && $_REQUEST['to_date']!='')
	$filter[]="dbl_dealer_dispatch.date BETWEEN '$from' and '$to'";
	
	
		
	
	if($filter!='')
	{
		$filter=implode(' and ',$filter);
	}
	if($_REQUEST['dealer']!='' && $_REQUEST['from_date']!='' && $_REQUEST['to_date']!='')
	{
	$message="Showing Records of Dealer ".$sitename."   From  ".$from." to ".$to."";
	}
	else if($_REQUEST['dealer']!='' && $_REQUEST['from_date']=='' && $_REQUEST['to_date']=='')
	{
	$message="Showing Records of Dealer ".$sitename." ";
	
	}
	else if($_REQUEST['dealer']=='' && $_REQUEST['from_date']!='' && $_REQUEST['to_date']!='')
	{
	$message="Showing Records   From  ".$from." to ".$to."";
	
	}
	if($filter!='')
	{
	
		$sql="Select * from dbl_dealer_dispatch where $filter and company='".$_SESSION['ACGCompanyId']."' 
		group by dbl_dealer_dispatch.id ";
    }
	else 
	{	   
	$sql ="Select * from dbl_dealer_dispatch and company='".$_SESSION['ACGCompanyId']."'  group by dbl_dealer_dispatch.id ";
	}
?>
<div align="center" class="row1"><strong><h1><?php echo $message; ?></h1></strong> </div>
<br />
  <table width="100%" cellpadding="0" cellspacing="0" border="1">
<tr class="row1" style="height: 30px">
<td width="40" class="tabledata"><strong>Sr No</strong></td>
<td width="40" class="tabledata"><strong>Sr No</strong></td>
<td width="60" class="tabledata"><strong>PickList Date</strong></td>
<td width="161" class="tabledata"><strong>Customer Name</strong></td>
<td width="60" class="tabledata"><strong>SOI No</strong></td>
<td width="60" class="tabledata"><strong>Against Enquiry</strong></td>
<td width="60" class="tabledata"><strong>Delivery date</strong></td>
<td width="114" class="tabledata" style="width:114px;"><strong>Part No</strong></td>
<td width="251" class="tabledata"><strong>Part Name </strong></td>
<td width="49" class="tabledata" style="width:49px;"><strong>UOM</strong></td>
<td width="49" class="tabledata" style="width:49px;"><strong>Order Qty</strong></td>
<td width="76" class="tabledata" style="width:76px;"><strong>Dispatch Qty</strong></td>
<td width="76" class="tabledata" style="width:76px;"><strong>Store</strong></td>
<td width="76" class="tabledata" style="width:76px;"><strong>GRN</strong></td>
 </tr>
    <?php 
  $s2=1;
  $result=DB_query($sql,$db);
  while($myrow=DB_fetch_array($result))
  {  
  ?>
<tr bgcolor="#FFFFFF">
<td  style="width:10px;" class="jjrs_tablehead"><?php echo $s2;?></td>
<td  style="width:50px;" class="jjrs_tablehead"><?php echo $myrow['pick_list_no'];?></td>
<td  style="width:120px;" class="jjrs_tablehead"><?php echo ConvertSQLDate($myrow['dispatch_date']);?></td>
<td  style="width:60px;" class="jjrs_tablehead"><?php echo $clientmaster=$s->getField('clientmaster','id',$myrow['customer'],'c_name');  ?></td>
<td  style="width:60px;" class="jjrs_tablehead"><?php echo $clientmaster=$s->getField('dbl_process_sale_order','id',$myrow['SOI_no'],'SOI_no');  ?></td>

<td  style="width:60px;" class="jjrs_tablehead"><?php echo $clientmaster=$s->getField('dbl_enquiry_form','id',$myrow['enquiry_no'],'form_no');  ?></td>
<td  style="width:60px;" class="jjrs_tablehead"><?php echo ConvertSQLDate($myrow['dispatch_date']);  ?></td>

<td colspan="9"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<?php 
$details_sql="Select * from dbl_dealer_dispatch_details where parentid='".$myrow['id']."'";
$details_res=DB_query($details_sql,$db);
$req_qty[]='';
$numrow1=DB_num_rows($details_res);
if(DB_num_rows($details_res)>0){
while($details_row=DB_fetch_array($details_res)){?>
<tr bgcolor="99CCCC">
<td width="112"  class="jjrs_tablehead"  style="width:125px;"><?php echo $s->getField('item_master','id',$details_row['mst_itemid'],'StockID'); ?></td>
<td width="157" class="jjrs_tabledata1" style="width:295px;"><?php echo $s->getField('item_master','id',$details_row['mst_itemid'],'item_name'); ?></td>
<td width="70" class="jjrs_tabledata1" style="width:45px;">
<?php   $unit=$s->getField('item_master','id',$details_row['mst_itemid'],'mst_unitid');
echo $s->getField('unitsofmeasure','unitid',$unit,'unitname'); ?> </td>
<td width="139" class="jjrs_tabledata1"  style="width:70px;"><span class="jjrs_tabledata1" style="width:70px;"><?php echo $details_row['order_qty'];
$issue_qty[]=$details_row['order_qty']; ?></span></td>
<td width="72" class="jjrs_tabledata1"  style="width:70px;"><?php echo $details_row['dispatch_qty'];
$req_qty[]=$details_row['dispatch_qty'];?></td>
<td width="72" class="jjrs_tabledata1"  style="width:70px;"><?php echo $s->getField('dbl_dealer_store','id',$details_row['dblstore'],'dealer_store_name');?></td>
<td width="72" class="jjrs_tabledata1"  style="width:70px;"><?php echo $s->getField('dbl_addmrn','id',$details_row['grnid'],'MRNNo');?></td>

        
          </tr>
          <?php } ?>
       
          <?php } ?>
        </table></td>
    </tr>
    <?php $s2++; } if($numrow1>0) { ?>
    <tr bgcolor="#e7e7e7" style="height: 25px">
      <td class="jjrs_tabledata1"><strong></strong></td>
      <?php if($_REQUEST['dealer']=='') { ?> <td class="jjrs_tabledata1">&nbsp;</td><?php } ?>
       <td class="jjrs_tabledata1">&nbsp;</td>
       <td class="jjrs_tabledata1"><strong>&nbsp;</strong></td>
      <td class="jjrs_tabledata1"><strong></strong></td>
	  <td class="jjrs_tabledata1"><strong></strong></td>
	   <td class="jjrs_tabledata1"><strong></strong></td>
	  <td class="jjrs_tabledata1"><strong></strong></td>
	   <td class="jjrs_tabledata1"><strong></strong></td>
	   <td class="jjrs_tabledata1"><strong></strong></td>
      <td class="jjrs_tabledata1"><strong>Total</strong></td>
      <td class="jjrs_tabledata1"><?php echo $c[]=array_sum($issue_qty);?></td>
      <td class="jjrs_tabledata1"><?php echo $b[]=array_sum($req_qty);?></td>
	  <td class="jjrs_tabledata1"><strong></strong></td>
	   <td class="jjrs_tabledata1"><strong></strong></td>
	  </tr>
      <?php } else { ?>
	   <tr bgcolor="#e7e7e7" style="height: 25px">
      <td class="jjrs_tabledata1" colspan="14" align="center"><strong>No Records</strong></td>
    </tr>
	  
      <?php } ?>     
    
  </table>

<?php } ?>
</div>
</div>