<script>
function show_assignment(str)
{
	$('#contractor'+str).show();
	$('#technician'+str).show();
	$('#assign'+str).hide();
}
function open_technician(str)
{
	//alert(str);
	window.open("open_technician_work_assignment.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>&bed_id=<?php echo str;?>","itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}

function project_order()
{
	$('#show_activity').show();
	$('#showsalesorder').hide();

}
function show_sales_order()
{
	$('#showsalesorder').show();
	$('#show_activity').hide();
}
</script>
<?php
   
    if($_REQUEST['Delete'])
 {
 	for($i=0;$i<count($_REQUEST['salesid']);$i++)
	{
	
	
	//-------Delete From salesOrder_deatils From Here-----------//
	
				$cond="masterId='".$_REQUEST['salesid'][$i]."'";
			    $row= $s->DeleteRecord('salesorder_details', $cond);
				
	//-------Delete From salesOrder_Comments End-----------//	
	
	
	//-------Delete From salesOrder_Comments From Here-----------//			
				
				$cond="sopno='".$_REQUEST['salesid'][$i]."'";
				$row=$s->DeleteRecord('salesorder_comments',$cond);
	//-------Delete From salesOrder_Comments End-----------//		
	
	
	//-------Delete From salesOrder_Comments From Here-----------//			
				
				$condas="parant_id='".$_REQUEST['salesid'][$i]."'";
				$row=$s->DeleteRecord('salesorder_hardware_items',$condas);
	//-------Delete From salesOrder_Comments End-----------//			
	
			
				
	//-------Delete From salesOrder_Comments From Here-----------//	
				
	 			$cond="id='".$_REQUEST['salesid'][$i]."'";
			    $row= $s->DeleteRecord('salesorder', $cond);
				
				
	//-------Delete From salesOrder_Comments End-----------//	
 	}
	 
  }
  
   if($_REQUEST['action']=='approv')
 {
 $data9['approval_status'] = '1';	
		$condition9="id='".$_REQUEST['cmpID']."'";
	 	$s->RecordEdit('project_completion',$data9,$condition9);
		$s->pageLocation("index.php?route=PMS/Transcations/ConvertBOQ".$rurl);

 }
  if($_REQUEST['action']=='convert')
 { 
 	$str = $s->GetfieldValue('salesorder',"id='".$_REQUEST['rid']."'",'orderNo');
 	// PROJECT NO
	 $strArray = (explode("/",$str));
	 $strArray[2];
	$projectNO = $str.'/P-'.substr($strArray[2],-3);
	
	// cost center no
	$cancat = 'C-'.substr($strArray[2],-3);
	$CostNO = $str.'/'.$cancat;
	
	$data['master_id']=$_REQUEST['rid'];
	$data['project_no']=$projectNO;
	$data['cost_center_no']=$CostNO;
		//print_r($data);exit();
		
		
		//extract($_REQUEST['sub_activity_defination']);
		if($s->RecordInsert('project_list',$data))
		{
		
	$dataE['project_status ']='1';
	$Cond="id='".$_REQUEST['rid']."'";
	$s->RecordEdit('salesorder',$dataE,$Cond);
		echo "<script>location.href='index.php?route=PMS/Transcations/ViewBOQ&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
		}
 
 }
 ?>
 <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;	
	}
	}
	

	
}

/*function open_technician(str,bran)
{
	var ttid=str;
	var branid=bran;
	window.open("open_technician_work_assignment.php?modid=<?php //echo $_REQUEST['modid'];?>&frmid=<?php //echo $_REQUEST['frmid'] ?>&action=<?php //echo $_REQUEST['action']?>&ttaid="+ttid+"&braid="+branid,"itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}*/

</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>RA Bill Creation</h1>
<form action="index.php?route=PMS/Transcations/ra_bill_detail<?php echo $rurl;?>" 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 height="29" 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">
&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" name="" value="Add New" class="search" onclick="show_sales_order();" style="cursor:pointer;corsor:hand;">&nbsp;&nbsp;<!--<input type="button" name="" value="Projects" class="search" onclick="project_order();" style="cursor:pointer;corsor:hand;">-->
</p>

<div style="width:100%;overflow:auto;display:none;" id="showsalesorder">
<table width="100%" border="1" cellpadding="3" cellspacing="0">
        <?php 
$query = "select project_completion.id as main_id,project_completion.boq_id as bid, project_assign_contractor.vendor_id as v_id, project_work_assignment.tech_id as t_id from project_completion left join  project_assign_contractor on project_completion.boq_id=project_assign_contractor.boq_id left join  project_work_assignment on project_completion.boq_id=project_work_assignment.boq_id where  project_completion.approval_status='1' and project_completion.ra_status=0 and project_completion.companyID='".$_SESSION['ACGCompanyId']."' GROUP BY vendor_id order by project_completion.date ASC";
$res = db_query($query,$db) or die(DB_error());
$i=1;
while($result = DB_fetch_array($res))
{
extract($result);

$paid=$s->GetFieldValue('boq_entry','id="'.$result['bid'].'"','salesorder_id');
$partyid=$s->GetFieldValue('manufacturing_advice','id="'.$paid.'"','partyid');
if($partyid!=0){

?>
	<input type="hidden" name="ra_type" value="<?php if(is_null($v_id)){echo 'T';}else{echo 'C';} ?>" />
	<input type="hidden" name="cont_id" value="<?php if(is_null($v_id)){echo $t_id;}else{echo $v_id;} ?>" />
        <tr>
          <td  style="padding-left:12px;"><strong>Project</strong></td>
          <td style="padding-left:12px;">
			<?php echo $s->GetfieldValue('manufacturing_advice',"id='".$paid."'",'project_name'); ?>		
		</td>
		<td  style="padding-left:12px;"><strong>Party</strong></td>
          <td style="padding-left:12px;">
			<?php echo $s->GetFieldValue('clientmaster','id='.$partyid.'','c_name'); ?>		
		</td>
		<td  style="padding-left:12px;"><strong>Advice No.</strong></td>
          <td style="padding-left:12px;">
			<?php echo $s->GetfieldValue('manufacturing_advice',"id='".$paid."'",'advice_no'); ?>			
		</td>
          <td style="padding-left:12px;">
            <input type="submit" name="addCont" class="search" value="Add" >
          </td>
        </tr>
        <tr>
          <td class="tabledata" style="padding-left:12px;"><strong>Sno</strong></td>
          <td class="tabledata" style="padding-left:12px;"><strong>PCS No</strong></td>
          <td class="tabledata" style="padding-left:12px;"><strong>PCS Date</strong></td>
          <td class="tabledata" style="padding-left:12px;"><strong>Project</strong></td>
          <td class="tabledata" style="padding-left:12px;"><strong>BOQ No</strong></td>
          <td class="tabledata" style="padding-left:12px;"><strong>BOQ Date</strong></td>
          <td class="tabledata" style="padding-left:12px;"><strong>Action</strong></td>
        </tr>
        <?php
if(is_null($v_id)){
$sql = "select project_completion.* from project_completion left join project_work_assignment on project_completion.boq_id=project_work_assignment.boq_id where  project_completion.approval_status='1' and project_completion.ra_status=0 and project_completion.companyID='".$_SESSION['ACGCompanyId']."' and project_work_assignment.tech_id='".$t_id."' order by project_completion.date ASC";
}else{
$sql = "select project_completion.* from project_completion left join  project_assign_contractor on project_completion.boq_id=project_assign_contractor.boq_id where  project_completion.approval_status='1' and project_completion.ra_status=0 and project_completion.companyID='".$_SESSION['ACGCompanyId']."' and project_assign_contractor.vendor_id='".$v_id."' order by project_completion.date ASC";
}
$result1 = db_query($sql,$db) or die(DB_error());
while($result12 = DB_fetch_array($result1))
{
extract($result12);
?>
        <tr>
          <td style="padding-left:12px;"><?php echo $i; ?></td>
          <td style="padding-left:12px;"><?php echo $pcs_no; ?></td>
          <td style="padding-left:12px;"><?php echo ConvertSQLDate($date); ?></td>
          <td style="padding-left:12px;"><?php echo $client; ?></td>
          <td style="padding-left:12px;"><?php echo $boq_no; ?></td>
          <td style="padding-left:12px;"><?php echo ConvertSQLDate($boq_date); ?></td>
          <td style="padding-left:12px;"><input type="checkbox" name="arrayItem[]" value="<?php echo $id; ?>"></td>
       </tr>
        <?php $i++; } }} ?>
      </table></td>
  </tr>
</table> 
</div>
<div id="show_activity">
<table width="100%" border="1" cellpadding="3" cellspacing="0">
	<tr>
		  	<td class="tabledata" style="padding-left:12px;"><strong>S. No.</strong></td>
			<td class="tabledata" style="padding-left:12px;"><strong>Branch</strong></td>
			<td class="tabledata" style="padding-left:12px;"><strong>Party</strong></td>
			<td class="tabledata" style="padding-left:12px;"><strong>Bill No.</strong></td>
			<td class="tabledata" style="padding-left:12px;"><strong>Bill Date</strong></td>
			<td class="tabledata" style="padding-left:12px;"><strong>Assign To</strong></td>
			<td class="tabledata" style="padding-left:12px;"><strong>Total Amount</strong></td>
			<td class="tabledata" style="padding-left:12px;"><strong>View</strong></td>
        </tr>
        <?php 
  $query = "select * from ra_bill where companyID='".$_SESSION['ACGCompanyId']."' order by bill_date DESC";
$res = db_query($query,$db) or die(DB_error());
$i=1;
while($result = DB_fetch_array($res))
{
extract($result);
?>
        <tr>
		  <td style="padding-left:12px;"><?php echo $i; ?></td>
		  <td style="padding-left:12px;"><?php echo $branch; ?></td>
          <td style="padding-left:12px;"><?php echo $s->GetfieldValue('clientmaster',"id='".$partyid."'",'c_name'); ?></td>
		  <td style="padding-left:12px;"><?php echo $bill_no; ?></td>
		  <td style="padding-left:12px;"><?php echo ConvertSQLDate($bill_date); ?></td>
		  <td style="padding-left:12px;"><?php if($ra_type=='C'){echo $s->GetfieldValue('suppliers',"id='".$assign_to."'",'vendor_name');}else{echo $s->GetfieldValue('technicians',"id='".$assign_to."'",'technician');} ?></td>
		   <td style="padding-left:12px;"><?php echo $gross_amt; ?></td>
		  <td style="padding-left:12px;"><a style="color:#000000;padding-left:12px;" href="index.php?route=PMS/Transcations/job_bill_detail_view&modid=25&frmid=618&action=view&jbid=<?php echo $id; ?>">
	<img width="15" height="15" src="images/search.gif"></a>
	</td>
        </tr>
		        
        <?php

$i++;  } ?>
      </table></td>
  </tr>
</table> 
</div>
</form>

</div>
</div>
