<?php 
$DeptId=$s->GetDeptIdByUser($_SESSION['UserID'],$_SESSION['ACGCompanyId']);
$DeptHead=$s->GetDeptHead($DeptId,$_SESSION['UserID'],'ComparativeApproval');

$indentQry="SELECT * FROM indentpr_mapping where  CompanyId='".$_SESSION['ACGCompanyId']."' and (quotaion_status='2' || quotaion_status='1' ) and createdBy='".trim($_SESSION['UserID'])."' and com_status='0' and site in('".$_SESSION['AssignedBranch']."') and postingDate between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."' and site in('".$_SESSION['AssignedBranch']."')";
$SQLVenQuo=DB_Query($indentQry,$db); 

?>
<style type="text/css">
.tab a{
color: #171717;
text-decoration: none;
font-weight: bold; display: block;
background-color:#99b998;
padding:5px 10px;
border:#778d77 solid 1px; border-top-left-radius: 5px;
    border-top-right-radius: 5px; 
}
.tab a:hover{
color: #171717;
text-decoration: none;
background-color:#fff;
}
#wrapper{
width:100%;
/*padding:0 10px;*/
box-sizing:border-box;
margin:auto;
}
.box{
background: #fff;
}
.boxholder{
clear: both;
padding:0;
padding-bottom:15px;
}
.tab{
float: left;
width: auto;
margin: 0 1px 0 0;
text-align: center;
/*background: #8DC70A url(images/greentab.jpg) no-repeat;*/
  margin-right:1px; margin-bottom: 1px;
}
.tabtxt{
margin: 0;
color: #fff;
font-size: 12px;
font-weight: bold;
padding:0 0 0 0;
}
</style>
<script type="text/javascript" src="js/prototype.lite.js"></script>
<script type="text/javascript" src="js/moo.fx.js"></script>
<script type="text/javascript" src="js/moo.fx.pack.js"></script>
<script type="text/javascript">
function init(){
	var stretchers = document.getElementsByClassName('box');
	var toggles = document.getElementsByClassName('tab');
	var myAccordion = new fx.Accordion(
		toggles, stretchers, {opacity: false, height: true, duration: 600}
	);
	//hash functions
	var found = false;
	toggles.each(function(h3, i){
		var div = Element.find(h3, 'nextSibling');
			if (window.location.href.indexOf(h3.title) > 0) {
				myAccordion.showThisHideOpen(div);
				found = true;
			}
		});
		if (!found) myAccordion.showThisHideOpen(stretchers[0]);
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php  echo  $page_title;?></h1>
<div id="wrapper">
<div id="content">
<div class="tab" title="Pending" style="padding:0px;border:none;"><div class="tabtxt"><a href="#">Pending </a></div></div>
<div class="tab" title="Comparison" style="border:none; padding:0px;"><div class="tabtxt"><a href="#">Comparison</a></div></div>
<div class="boxholder">

<div class="box">
<h3>Pending</h3>
    <table width="100%" border="0" cellpadding="3" cellspacing="0" >
    <tr>
         <td width="6%">
            <div style="width:25px;height: 25px;background-color:#fff7e9;margin-left: 30px;border-radius:2px; border:#ccc 1px solid;" ><span style="margin-left:30px;">Partial</span></div>
        </td>
        <td width="6%">
            <div style="width:25px;height: 25px;background-color:#e8ffe8;margin-left: 30px;border-radius:2px; border:#ccc 1px solid;" ><span style="margin-left:30px;">Complete</span></div>
        </td>
        <td width="26%">            
        </td>        
    </tr> 
</table>
<table border="1" cellpadding="3" cellspacing="0" width="100%" style="border:1px #808080 solid;">
<tr>
	<th width="5%" rowspan="2">S. No.</th>
    <th width="12%" rowspan="2">RFQ No.</th>
	<th width="9%" rowspan="2">RFQ Date</th>
	<th rowspan="2">Against Requisitions</th>
    <th width="10%" rowspan="2">Requisitions Date</th>
    <!-- <th rowspan="2">Items</th>
    <th rowspan="2">Qty.</th>-->
    <th width="10%" rowspan="2">Type</th>
    <th width="7%" rowspan="2">No. of Quotations</th>
	<th colspan="2" style="text-align: center;">Action</th>
</tr>
<tr>   
	<th width="5%" style="text-align: center;">Print</th>
	<?php if($_SESSION['frmcreate']==1){?><th width="7%" style="text-align: center;">Comparison</th><?php } ?>
	<!--<?php if($_SESSION['frmView']==1){?><td>View</td><?php } ?>-->	
</tr>
<?php  
if(DB_num_rows($SQLVenQuo)>0)
{
	$i=0; 
	while($QuotDetails=DB_fetch_array($SQLVenQuo))
	{
    	$maxAssign="select max(no_of_assignee) as numMax from conf_purch_approval where company_id='".$_SESSION['ACGCompanyId']."' and doc_type='CP'";
		$maxAssignExec=DB_query($maxAssign,$db);
		$maxAssignDATA=DB_fetch_array($maxAssignExec);
 		$maximAss=$maxAssignDATA['numMax'];
 
 		$approvalQry="select approval_status from cp_head_approval where sr_no='".$maximAss."' and cp_no='".$QuotDetails['id']."'";
 		$approvalQryExec=DB_query($approvalQry,$db);
		$approvalQryDATA=DB_fetch_array($approvalQryExec);
		$approvalFlag=$approvalQryDATA['approval_status'];
		if($approvalFlag=='1')
		{
    		$color='#e8ffe8';
		}
 		else 
 		{
     		$color='#fff7e9';
		}
?>
<tr bgcolor="<?php echo $color; ?>">
	<td ><?php echo ($i+1).'.';?></td>
	<td ><?php echo $QuotDetails['mapNo'];?></td>
	<td ><?php echo ConvertSQLDate($QuotDetails['createdDate']);?></td>        
    <td ><?php 
        $ReqArray=explode(',', $QuotDetails['indentPrno']);
       foreach($ReqArray as $reqID)
       {
          echo $s->GetFieldValue('materialrequisitions',"requisitionno='".$reqID."'",'Reqno').'<br/>'; 
       }
       ?></td>        
    <td ><?php 
        $ReqArray=explode(',', $QuotDetails['indentPrno']);
       foreach($ReqArray as $reqID)
       {
           $reqDate=$s->GetFieldValue('materialrequisitions',"requisitionno='".$reqID."'",'prdate');
           echo ConvertSQLDate($reqDate).'<br/>';
       }
       ?></td>        
       <!-- <td ><?php 
        $itemArray=explode(',', $QuotDetails['ItemID']);
       foreach($itemArray as $itemids)
       {
          echo $s->GetFieldValue('item_master',"id='".$itemids."'",'item_name').'<br/>'; 
       }
       ?></td>
        
        <td ><?php 
        $qtyArray=explode(',', $QuotDetails['mappedQty']);
        foreach($qtyArray as $quantity)
            {
               echo $quantity.'<br/>'; 
            }
       ?></td>-->        
    <td ><?php 
        
        if($QuotDetails['flag']=='true'){
            echo 'Consolidated';
        }
 else {
     echo 'Individual';
 }
         ?></td>
    <td style="text-align:right;">
            <?php
            $noQuoQry="select id from venderquotations where mapid='".$QuotDetails['id']."' and CompanyId='".$_SESSION['ACGCompanyId']."'";
            $noQuoQryExec = DB_query($noQuoQry, $db);
            echo $numRows=DB_num_rows($noQuoQryExec);
            ?>
    </td>
    <td style="text-align:center;"><a target="_blank" href="vendor_quotations.php?id=<?php echo $QuotDetails['id']; ?>"><img width="18" height="18" src="images/icon_print.jpg" title="Print" /></a></td>
	<td style="text-align:center;">	
	<?php 
        $approvCongig= $s->GetFieldValue('conf_purch_approval',"doc_type='CP'",'chk_approve');
        $approvCongigmainID= $s->GetFieldValue('conf_purch_approval',"doc_type='CP'",'id');
             
        if($approvCongig=='1') {
            // get Approval Status
        if($approvalFlag==1){  ?>
	<a href="index.php?route=POModule/Comperitive_new&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&RequisitionNo=<?php echo $QuotDetails['indentPrno']; ?>&flag=<?php echo $QuotDetails['flag']; ?>&mapid=<?php echo $QuotDetails['id']; ?>"><input type="button" value="Create" class="search" /></a>
		<?php }else{?>
	<input type="button" value="Create" class="search" title="Unapproved"/>	
	<?php }
        }
 else {
     // Check OPening Date Validation
     $date1=date('Y-m-d');
     $date2=$QuotDetails['openingDate'];
      if(strtotime($date2) <= strtotime($date1)){ ?>
	<a href="index.php?route=POModule/Comperitive_new&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&RequisitionNo=<?php echo $QuotDetails['indentPrno']; ?>&flag=<?php echo $QuotDetails['flag']; ?>&mapid=<?php echo $QuotDetails['id']; ?>"><input type="button" value="Create" class="search" /></a>
		<?php }else{?>
	<input type="button" value="Create" class="search" title="valid From Opening Date Only"/>
	
	<?php }
 }
        ?>	
	</td>        
	<!--<?php if($_SESSION['frmView']==1){?><td> <div align="center"><a href="index.php?route=POModule/purchase_requisition_view&modid=<?php echo $_REQUEST['modid']?>&frmid=<?php echo $_REQUEST['frmid']?>&RequisitionNo=<?php echo $PrIndentData['requisitionno'];?>"><img src="images/search.gif" width="15" height="15"></a></div></td><?php } ?>-->	
	</tr>
<?php $i++;} }else{?>
<tr class="row1">
	<td colspan="11" style="color:red;">No Record Found !! </td>
</tr>
<?php } ?>
</table>
</div>

<div class="box">
<h3>Comparison</h3>    
<table border="1" cellpadding="3" cellspacing="0" width="100%" style="border:1px #808080 solid;">
<tr>
	<th width="12%">Comparison Number</th>
	<th width="10%">Comparison Date</th>
	<th>Vendor</th>
	<th width="10%">PO Status</th>	
	<th width="5%" style="text-align:center;">Print</th>
	<th width="5%" style="text-align:center;">Delete</th>
</tr>
<?php 

 $sql = "SELECT A.id AS PID,A.site,A.comparative_no,A.comparative_date,B.*
		FROM comprative A INNER JOIN comprative_detail B ON(A.id=B.parant_id) where  po_del_status=0 and  A.site in('".$_SESSION['AssignedBranch']."') and comparative_date between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."'
		GROUP BY A.id ";
 
$PurchOrdersResult = DB_query($sql,$db);

$j = 1;
$k=0; //row colour counter
$poStatus=0;
if(DB_num_rows($PurchOrdersResult)>0)
{
	while ($row=DB_fetch_array($PurchOrdersResult)) 
	{
           
$ChkPO=DB_query("SELECT * FROM purchorders where comperativeId='".$row['PID']."' and vendorId='".$row['sppliersId']."'",$db);
if(DB_num_rows($ChkPO)>0)
{
	$poStatus='1';
}
else
{
	$poStatus='0';
}

?>
<tr>
	<td><?php echo $row['comparative_no'];?></td>
	<td><?php echo ConvertSQLDate($row['comparative_date']);?></td>
 	<td><?php echo  $s->GetFieldValue('suppliers',"id='".$row['sppliersId']."'" ,'vendor_name');;?></td>
	<td><?php 
        //echo $poStatus;
	if($poStatus=='1')
	{
		echo 'PO Generated';
	}
	else
	{
		echo 'Not Generated';
	}
?></td>
<td style="text-align:center;"><a href="approval_memo.php?id=<?php echo $row['PID']; ?>" target="_blank"><img src="images/icon_print.jpg" height="18" width="18" title="Print" ></a>
<!--<?php 	
if($poStatus!='1'){
$po_frmid=$s->GetFieldValue('modules_form',"frm_url='POModule/view_purchase_order'" ,'id');
	?>
	<a href="index.php?route=POModule/create_process_po_order&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $po_frmid ?>&CPID=<?php echo $row['PID']?>&SupplierId=<?php echo $row['sppliersId'] ?>&site=<?php echo $row['site'];?>"><input type="button" value="Create Purchase Order" class="search" /></a>
<?php }else{ ?>
	<input type="button" value="PO Generated" class="search" />
	
	<?php } ?>-->
</td>
	<td style="text-align:center;"><img src="images/Icon_Delete.png" width="15" height="15" title="Delete" /></td>
</tr>
<?php  $j++; }}else{?>
<tr>
	<td colspan="6" style="text-align:center;"><font color="#FF0000">No Record Found!</font></td>
</tr>
<?php }?>
</table>
</div>
</div>

</div>
</div>

<?php if(isset($_SESSION['success_msg']))
{ ?>
	<script> alert("<?php echo ($_SESSION['success_msg']);?>");</script>
<?php 
}	unset($_SESSION['success_msg']);
?>
<script type="text/javascript">
	Element.cleanWhitespace('content');
	init();
</script>

</div>
</div>