<?php include('functions.php');
include('functionsgetdep.php');
include('includes/Class_Client.php');
include('Class_PickListEditor.php');
$date=date('Y-m-d');
$back_days=calculateBackDate($_SESSION['ACGRoleId']);
$back_date=date('Y-m-d', strtotime('-'.$back_days.' day', strtotime($date)));
?><?php
    $catid= $s->GetFieldValue('crm_picklist',"picklist_title='Leads' and status=1",'picklist_id');
   $table="crm_accounts";
   
    if($_REQUEST['Delete'])
 {
 	for($i=0;$i<count($_REQUEST['salesid']);$i++)
	{
	
	//-------Delete From salesOrder_deatils From Here-----------//
	
				$cond="parent_id='".$_REQUEST['salesid'][$i]."'";
			    $row= $s->DeleteRecord('indent_so_main_details', $cond);
				

			
				
	//-------Delete From salesOrder_Comments From Here-----------//	
				
	 			$cond="id='".$_REQUEST['salesid'][$i]."'";
			    $row= $s->DeleteRecord('indent_so_main', $cond);
				
				
	//-------Delete From salesOrder_Comments End-----------//	
 	}
	 
  }
 
 ?>
 <script language="javascript" >
function LeadData()
{	

	myCheckboxArray = document.myform.elements["salesid[]"];
	var t=myCheckboxArray.length;
	
	
	if(document.getElementById('salesid').checked==true)
	{	
	
		if(t==undefined)
	
		document.getElementById('salesid_'+1).checked=true;		
			for (var i = 1; i <= t; i++)
	{
	document.getElementById('salesid_'+i).checked=true;	
	}	
	}
	else
	{
	if(t==undefined)		
		document.getElementById('salesid_'+1).checked=false;		
			
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('salesid_'+i).checked=false;	
	}
	}
	

	
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Fabrication Sheet </h1>
<form action="" method="post" name="myform" >
<div class="centre" id="slidingDiv">
<table width="100%" cellpadding="3" cellspacing="0">
  <tr class="row1">
    <td class="tabledata1">Branch</td>
	<td colspan="3" class="tabledata1">
	<select name="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>
	</tr>
	 <tr class="row1">
	<td class="tabledata1">From:</td>
	<td class="tabledata1">
	<input name="fromdate" value="<?php echo $_REQUEST['fromdate']; ?>" type="text" style="width:150px;"  class="datepicker"/></td>
	<td class="tabledata1">To:</td>
	<td class="tabledata1">
	<input name="todate" value="<?php echo $_REQUEST['todate']; ?>" type="text" style="width:150px;"  class="datepicker"/></td>
	</tr>
	<tr class="row1">
	<td colspan="4"><p align="center"><input name="Search" type="submit"  value="Search" class="search"/></p></td>
  </tr>
</table> 
</div>	
<p align="left">

<?php if($_SESSION['frmDelete']==0){ ?>
<input type="button" name="Delete" value="Delete" alt="Not Allowed" title="Not Allowed" class="search" />
<?php }else{?>	 
<input type="submit" name="Delete" value="Delete" class="search" />
<?php }?> 

<input type="button" name="Add New" value="Add New" class="search" onclick="showdata()" />

</p>

<div style="width:100%; overflow:auto; display:none;" id="show1" >
<table width="100%" border="1" cellpadding="3" cellspacing="0">
  <tr>
    <td class="tabledata"><input name="salesid" type="checkbox"   id="salesid" onclick="LeadData()"    />  </td>
	<td class="tabledata"><strong>Date</strong></td>
	<td class="tabledata"><strong>MMS No </strong></td>
	<td class="tabledata"><strong>Client Name</strong></td>
	<td class="tabledata"><strong>PO No.</strong></td>
	<td class="tabledata"><strong>PO Date.</strong></td>
	<td class="tabledata"><strong>Order Type</strong></td>
	<td class="tabledata"><strong>Created By</strong></td>	
	<td class="tabledata"><strong>Action</strong></td>
	
  </tr>
<?php 
$s=new db_query();

if($_REQUEST['Search'])
	{
	$todate=ConvertSQLDate($_REQUEST['todate']);
	$fromdate=ConvertSQLDate($_REQUEST['fromdate']);
	$site=$_REQUEST['site'];
	if($_REQUEST['todate']!='' && $_REQUEST['fromdate']!='' )
	{
	$filter[]="mms_date between '".$todate."' and '".$fromdate."'";
	}
	if($_REQUEST['site']!='0')
	{
	$filter[]="site='".$site."'";
	}
	if($_REQUEST['site']=='0')
	{
	$GetSales= "select * from measurment_sheet_main";
	$getlead=DB_query("select * from measurment_sheet_main where CompanyID='".$_SESSION['ACGCompanyId']."'
	  order by id desc ",$db);
	}
	if($filter!='')
	{
	$filter1=implode(" and ",$filter);
	$GetSales="select * FROM measurment_sheet_main   
	where CompanyID='".$_SESSION['ACGCompanyId']."'  and $filter1 ";

	$getlead=DB_query($GetSales,$db);
	}
}

else 
{
	$i=1;
	
	 $GetSales="SELECT * FROM measurment_sheet_main where CompanyID='".$_SESSION['ACGCompanyId']."' ORDER BY id DESC";
		  
	$getlead=DB_query($GetSales,$db);
	}
  
$lop=0;
 if(DB_num_rows($getlead)>0)
{
	 while($row_quotes=DB_fetch_array($getlead))
	 {
	  // $row_quotes['client'];

	   //$ClientName=$Class_Client->GetClientByLedger($row_quotes['client']);
	   $ClientName=$s->getField('clientmaster','id',$row_quotes['client'],'c_name');
	   	   
    $SO_VIEW="index.php?route=CRM/measermentView&action=View&SOrderId=".$row_quotes['id'].$rurl;
    $SO_print="indentprint.php?action=View&SOrderId=".$row_quotes['id'].$rurl;
	
    
	 ?>

    <tr  style="border:1px thin;">
    <td style="white-space:nowrap;" valign="top">
  
   
<?php if($_SESSION['frmView']==0){ ?>
<img src="images/search.gif" width="20px" alt="Not Allowed" title="Not Allowed"  height="20" />
<?php }else {?>
<a href="<?php echo $SO_VIEW?>" ><img src="images/search.gif" width="20px"  height="20" /></a>
<?php } ?>

	
</td>
  <td valign="top"> <p>
    <?php  echo ConvertSQLDate($row_quotes['mms_date']); //echo "==="; echo $back_date;
	?>
</p>
    </td>
  <td valign="top" style="white-space:nowrap"></center>
    <?php  echo $row_quotes['mms_no']; ?></td>
<td valign="top" style="white-space:nowrap"><?php // echo $s->GetFieldValue('accountledger',"AccountsID='".$row_quotes['client']."'  ",'AccountName'); $row_lead['party']?></center>
<?php echo $ClientName;//."--".$czone ?>
	</td>
	<td valign="top"><?php  echo $row_quotes['po_no']?></td>
	<td valign="top"><?php  echo ConvertSQLDate($row_quotes['po_date']);?></td>
	<td valign="top"><?php echo $row_quotes['order_type']; ?></td>
	<td valign="top"><?php  echo $s->GetFieldValue('www_users',"id='".$row_quotes['created_by']."'",'realname'); ?>	</center></td>
	<td valign="top"><?php if($row_quotes['stauts']=='Pending') { ?>
	<a href="index.php?route=CRM/fabrication_sheet&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&id=<?php  echo $row_quotes['id']; ?>"><input type="button" name="Farb" value="Fabrication Sheet" class="search" /></a>
	<?php } else { echo  "Fabrication Sheet Already Prepared";  }?>
	</td></tr>
   <?php   }
   $lop++; }  
   else
   {?>
   	<tr>
   		<td colspan="14"><font color="#FF0000"><?php echo "No Records Found"; ?></font></td>
	</tr>
  <?php }?>
</table>
	</div>
	<div style="width:100%; overflow:auto;" id="hide1" >
<table width="100%" border="1" cellpadding="3" cellspacing="0">
  <tr>
    <td class="tabledata"><input name="salesid" type="checkbox"   id="salesid" onclick="LeadData()"    />  </td>
	<td class="tabledata"><strong>Date</strong></td>
	<td class="tabledata"><strong>Sheet No</strong></td>
	<td class="tabledata"><strong>Client Name</strong></td>
	<td class="tabledata"><strong>Against MMS.</strong></td>
	<td class="tabledata"><strong>MMS Date.</strong></td>
	<td class="tabledata"><strong>Order Type</strong></td>
	<td class="tabledata"><strong>Created By</strong></td>	
	
	
  </tr>
<?php 
$s=new db_query();


if($_REQUEST['Search'])
	{
	$todate=ConvertSQLDate($_REQUEST['todate']);
	$fromdate=ConvertSQLDate($_REQUEST['fromdate']);
	$site=$_REQUEST['site'];
	if($_REQUEST['todate']!='' && $_REQUEST['fromdate']!='' )
	{
	$filter[]="sheet_date between '".$todate."' and '".$fromdate."'";
	}
	if($_REQUEST['site']!='0')
	{
	$filter[]="site='".$site."'";
	}
	if($_REQUEST['site']=='0')
	{
	$GetSales= "select * from faberication_main   ";
	$getlead=DB_query("select * from faberication_main where CompanyID='".$_SESSION['ACGCompanyId']."'
	  order by id desc ",$db);
	}
	if($filter!='')
	{
	$filter1=implode(" and ",$filter);
	$GetSales="select * FROM faberication_main   
	where CompanyID='".$_SESSION['ACGCompanyId']."'  and $filter1 ";

	$getlead=DB_query($GetSales,$db);
	}
}

else 
{
	$i=1;
	
	 $GetSales="SELECT * FROM faberication_main where CompanyID='".$_SESSION['ACGCompanyId']."' ORDER BY id DESC";
		  
	$getlead=DB_query($GetSales,$db);
	}
  
$lop=0;
 if(DB_num_rows($getlead)>0)
{
	 while($row_quotes=DB_fetch_array($getlead))
	 {
	 $ClientName=$s->getField('clientmaster','id',$row_quotes['client'],'c_name');	 
	 
	 
	 
	 
	   
	
	$SOURL="index.php?route=CRM/FabricationEdit&action=Edit&SOrderId=".$row_quotes['id'].$rurl;
    $SO_VIEW="index.php?route=CRM/FabricationView&action=View&SOrderId=".$row_quotes['id'].$rurl;
    $SO_print="Fabricationprint.php?action=View&SOrderId=".$row_quotes['id'].$rurl;

	 ?>

    <tr  style="border:1px thin;">
    <td style="white-space:nowrap;" valign="top">
  
   <input name="salesid[]" type="checkbox" id="salesid_<?php echo $lop+1; ?>"   value="<?php  echo $row_quotes['id']?>"  />
<?php if($_SESSION['frmEdit']==0){ ?>
<img src="images/icon_edit.gif" width="10px" alt="Not Allowed" title="Not Allowed"  height="20" />
<?php }else {?>
<a href="<?php echo $SOURL?>"><img src="images/icon_edit.gif" width="20px"  height="20" /></a>
<?php } ?>

<?php if($_SESSION['frmView']==0){ ?>
<img src="images/search.gif" width="10px" alt="Not Allowed" title="Not Allowed"  height="20" />
<?php }else {?>
<a href="<?php echo $SO_VIEW?>" ><img src="images/search.gif" width="20px"  height="20" /></a>
<?php } ?>


<a href="<?php echo $SO_print?>" target="_blank" ><img src="images/icon_print.jpg" width="20px"  height="20" /></a>

</td>
  <td valign="top" > <p>
    <?php  echo ConvertSQLDate($row_quotes['sheet_date']); //echo "==="; echo $back_date;
	?>
</p>
    </td>
  <td valign="top" style="white-space:nowrap"></center>
    <?php  echo $row_quotes['sheet_no']; ?></td>
<td valign="top" style="white-space:nowrap"><?php // echo $s->GetFieldValue('accountledger',"AccountsID='".$row_quotes['client']."'  ",'AccountName'); $row_lead['party']?></center>
<?php echo $ClientName;//."--".$czone ?>
	</td>
	<td valign="top"><?php  echo $s->getField('measurment_sheet_main','id',$row_quotes['against_indent'],'mms_no')?></td>
	<td valign="top"><?php  echo ConvertSQLDate($s->getField('measurment_sheet_main','id',$row_quotes['against_indent'],'mms_date'));?></td>
	<td valign="top"><?php echo $row_quotes['type_of_sheet']; ?></td>
	
	
	<td valign="top"><?php  echo $s->GetFieldValue('www_users',"id='".$row_quotes['created_by']."'",'realname'); ?>
	
	</center></td>
	
	
   </tr>
   <?php   }
   $lop++; }  
   else
   {?>
   	<tr>
   		<td colspan="14"><font color="#FF0000"><?php echo "No Records Found"; ?></font></td>
	</tr>
  <?php }?>
</table>
	</div>
</form>
</div>
</div>

<script>

function showdata()
{
document.getElementById("show1").style.display='block';
document.getElementById("hide1").style.display='none';
}


</script>