<?php
include("Class_Party.php");
include("Class_Branch.php");
?>

<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php echo $s->GetFieldValue('modules_form',"id='".$_REQUEST['frmid']."'",'description'); ?></h1>
<div id="slidingDiv">
<form action="" method="post">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
    <tr class="row1">
      <td class="tabledata1" style="width:146px;">Branch</td>
      <td><?php echo $ClassBranch->SiteRecord('site',$_REQUEST['site'],'leads');?>
      </td>
      <td class="tabledata1" style="width:146px;">Movement</td>
      <td><?php  $doc=array("I" =>"Incoming","O" =>"Outgoing"); ?>
	<select name="doc" id="doc" style="width:150px;">
            <option value="0"<?php echo ($_REQUEST['doc']=='0'?'selected':'')?>>All</option>
	<?php foreach($doc as $keyDocs => $docs){?>
	<option value="<?php echo $keyDocs; ?>"<?php echo ($_REQUEST['doc']==$keyDocs?'selected':'')?>><?php echo $docs;?></option>
	<?php } ?>
	</select></td>
        
        <td class="tabledata1">Document From/To</td>
	<td>
	<?php  $doctype=array("V" =>"Vendor","C" =>"Client","G" =>"General","O" =>"Other","B" =>"Branch"); ?>
	<select name="doc_Type" id="doc_Type" style="width:150px;" onchange="getTypeDetails(this.value)">
            <option value=""<?php echo ($_REQUEST['doc_Type']==''?'selected':'')?>>All</option>
	<?php foreach($doctype as $keyDoc => $docName){?>
	<option value="<?php echo $keyDoc; ?>"<?php echo ($_REQUEST['doc_Type']==$keyDoc?'selected':'')?>><?php echo $docName;?></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 colspan="3"><input name="ToDate" id="ToDate" type="text"  class="datepicker" style="width:150px;"  value="<?php echo $_REQUEST['ToDate'];?>" /></td>
    </tr>
<tr class="row1">
	<td colspan="6"><p align="center"><input type="submit" name="Search" value="Search" class="search" /></p></td>
</tr>
  </table>
</form>
</div>
<?php  
 if($_REQUEST['Search']){
 
 if($_REQUEST['site']!='')	
 $filter[]="branch ='".$_REQUEST['site']."'";
 
  if($_REQUEST['doc']!='0')	
 $filter[]="doc ='".$_REQUEST['doc']."'";
  
  if($_REQUEST['doc_Type']!='')
 $filter[]="doc_Type='".$_REQUEST['doc_Type']."'";
 
 
 $filter[]="CompanyId='".$_SESSION['ACGCompanyId']."'";
 


	if($_REQUEST['frmDate'] && $_REQUEST['ToDate']!='')
	 $filter[]="doc_date between '".ConvertSQLDate($_REQUEST['frmDate'])."' and '".ConvertSQLDate($_REQUEST['ToDate'])."' ";
	
	if($filter!='')
	{
		$filter=implode(" and ",$filter);
		$mainSql="Select * from dms_doc_type where $filter";
	}
 ?>

<?php
 
}else{
$mainSql="Select * from dms_doc_type where CompanyId='".$_SESSION['ACGCompanyId']."'";
}
 $i=1;
 
 //echo $mainSql;
$mainRes=DB_query($mainSql,$db);
?>

<table width="100%" border="1" cellpadding="3" cellspacing="0">
  <tr class="row1">
      <td width="4%" class="tabledata">Sr. No.</td>
      <td width="7%" class="tabledata">Document Date</td>
    <td width="7%" class="tabledata">Document No</td>
    <td colspan="2" align="center" class="tabledata" style="text-align:center;">Document From/To</td>
    <td width="7%" class="tabledata">Movement</td>
    <td width="15%" class="tabledata">Subject</td>
    <td width="15%" class="tabledata">Document Type</td>
    <td class="tabledata">Document</td>
   </tr>
  <?php 
   if(DB_num_rows($mainRes)>0){
while($mainRow=DB_fetch_array($mainRes))
{
    $data1='';
    $data2='';
    $type=$mainRow['doc_Type'];
    if($type=='V'){
    $data1='Vendor';
    ?>
    <?php
    $data2.=$s->GetFieldValue('suppliers',"id='".$mainRow['doc_id']."'",'vendor_name');
}

elseif($type=='C') {
$data1='Client';
$data2.=$s->GetFieldValue('clientmaster',"id='".$mainRow['doc_id']."'",'c_name');
 }
 
 elseif($type=='G') {
$data1='General';
$data2=$mainRow['doc_id'];
 }
 elseif($type=='O') {
$data1='Other';
$data2=$mainRow['doc_id'];
 }
 elseif($type=='B') {
$data1='Branch';
$data2.=$s->GetFieldValue('locations',"loccode='".$mainRow['doc_id']."'",'locationname');
 }
?>
<tr class="row1">
    <td style="padding-left:5px; padding-right:5px;white-space:nowrap;"><?php echo $i.' .';?> </td>
    <td style="padding-left:5px; padding-right:5px;white-space:nowrap;"><?php echo ConvertSQLDate($mainRow['doc_date']);?> </td>
    <td style="padding-left:5px; padding-right:5px;white-space:nowrap;"><?php echo $mainRow['doc_no'];?> </td>
    <td width="5%" style="padding-left:5px; padding-right:5px;white-space:nowrap;"><?php echo $data1;?></td>
    <td width="25%" style="padding-left:5px; padding-right:5px;white-space:nowrap;"><?php echo $data2;?> </td>
    <td style="padding-left:5px; padding-right:5px;white-space:nowrap;"><?php if($mainRow['doc']=='I') { echo 'Incoming'; } elseif($mainRow['doc']=='O') { echo 'Outgoing'; } ?> </td>
    <td style="padding:0px;" colspan="3">
        <table width="100%" border="0" cellpadding="3" cellspacing="0">
            <?php
            $detDta="select * from dms_doc_type_dtls where parent_id='".$mainRow['id']."'";
        $detDtaExec=DB_query($detDta,$db);
        
        while ($detRow=DB_fetch_array($detDtaExec))
	  {
            ?>
            <tr  bgcolor="#ADD8E6">
                <td width="186" style="border-right:#808080 1px solid;"><?php echo $detRow['doc_name'];?> </td>
                <td width="187" style="border-right:#808080 1px solid;"><?php echo $s->GetFieldValue('dms_doc_type_mstr',"id='".$detRow['doc_type_mstr_id']."'",'doc_type_name');?> </td>
                <td><a href="uploaded_docs/<?php echo $detRow['doc_file_name']; ?>" target="_blank"><?php echo $detRow['doc_file_name'];
                ?></a></td>
            </tr>
<?php } ?>
        </table>
    </td>
      </tr>
  <?php
$i++;	
}
?>
  <? } else { ?>
  <tr class="row1">
      <td style="padding-left:5px; padding-right:5px;white-space:nowrap;color:red;" colspan="10">No Record Found!!</td>
  </tr>
  <? } ?>
</table>


</div></div>