<style>
    .inner{
        color: #00463f;
        font-family: sans-serif;
        font-weight:bold;
        font-size: 12px;
    }
</style>
<?php 
 $QUERYNew="select requiDetIds FROM indentpr_mapping a where CompanyId='".$_SESSION['ACGCompanyId']."' and id not in ('".$_REQUEST['indentID']."')";
$QUERYNewExec=DB_query($QUERYNew,$db);
while($indreqDEtId=DB_fetch_array($QUERYNewExec))
{
   $redetid[]= $indreqDEtId['requiDetIds'];
}


 $QUERYNew1="select requiDetIds FROM indentpr_mapping a where CompanyId='".$_SESSION['ACGCompanyId']."' and id in ('".$_REQUEST['indentID']."')";
$QUERYNewExec1=DB_query($QUERYNew1,$db);
while($indreqDEtId1=DB_fetch_array($QUERYNewExec1))
{
   $redetid1[]= $indreqDEtId1['requiDetIds'];
}
$result=array_diff($redetid,$redetid1);

$reqidsStrs=implode(',', $result);
$k=0;
$maxAssign="select max(no_of_assignee) as numMax from conf_purch_approval where company_id='".$_SESSION['ACGCompanyId']."' and doc_type='PR'";
$maxAssignExec=DB_query($maxAssign,$db);
$maxAssignDATA=DB_fetch_array($maxAssignExec);
 $maximAss=$maxAssignDATA['numMax'];
 
$indentid=$_REQUEST['indentID'];
 
$QUERY="select * FROM indentpr_mapping a where CompanyId='".$_SESSION['ACGCompanyId']."' and id='".$indentid."'";
$Indent=DB_query($QUERY,$db);
$GetIndentReqID=DB_fetch_array($Indent);
$reqMainId= $GetIndentReqID['indentPrno'];
$reqDetaId= $GetIndentReqID['requiDetIds'];
$reqIdArray=explode(',', $reqMainId);
$reqDetIdArray=explode(',', $reqDetaId);
$flag= $GetIndentReqID['flag'];

//print_r($reqDetIdArray);
?>

 
 <table width="100%" border="0" cellpadding="3" cellspacing="0" >
    <tr>
        <td width="10%">
            <div style="width:25px;height: 25px;background-color:#B8B8B8;margin-left: 30px;border-radius:2px;" ><span style="margin-left:30px;">Pending</span></div>
        </td>
        <td width="10%">
            <div style="width:25px;height: 25px;background-color:#FFFF33;margin-left: 30px;border-radius:2px; verticle-align:middle;" ><span style="margin-left:30px;">Partial</span></div>
        </td>
        <td width="10%">
            <div style="width:25px;height: 25px;background-color:#e4e4e4;margin-left: 30px;border-radius:2px; verticle-align:middle;" ><span style="margin-left:30px;">Complete</span></div>
        </td>
        <td>
            <?php if($flag=='false') { ?>
    <input type="checkbox" name="consolidate" id="consolidate" value="C" />Consolidate
    <?php } else { ?>
    <input type="checkbox" name="consolidate" id="consolidate" checked value="C" />Consolidate
    <?php } ?>
        </td>
    </tr> 
</table>
<table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
 <input type="hidden" name="mainIndentID" id="mainIndentID" value="<?php echo $indentid; ?>" />  

<tr>
    <th width="4%">S. No.</th>
    <th width="12%">Item Code</th>
    <th>Item Name</th>
    <th width="8%">UOM</th>
    <th width="10%">Qty.</th>
    <th width="7%">Action</th>
</tr> 
<?php  foreach($reqIdArray as $reqMainID){
    
    $status=$s->GetFieldValue('materialrequisitions',"requisitionno='".$reqMainID."'",'mapped_vendor_status');
    if($status==0)
    {
        $color='#B8B8B8 ';
    }
    elseif($status==1)
    {
        $color='#e4e4e4';
    }
    elseif($status==2)
    {
        $color='#FFFF33';
    }
   
    ?>
<tr style="background-color:<?php echo $color; ?>">	
	<th colspan="6" style="font-weight:normal;">  
    <?php 
    $GetPendIndent['sitecode']=$s->GetFieldValue('materialrequisitions',"requisitionno='".$reqMainID."'",'sitecode');
    echo 'Branch: <span class="inner">'.$s->GetFieldValue('locations',"loccode='".$GetPendIndent['sitecode']."'",'locationname').'</span>'; ?>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
    <input type="hidden" name="site" value="<?php echo $GetPendIndent['sitecode']; ?>" id="site">  
	<?php 
        $GetPendIndent['requition_by']=$s->GetFieldValue('materialrequisitions',"requisitionno='".$reqMainID."'",'requition_by');
        echo 'Indent By: <span class="inner">'.$s->GetFieldValue('empmaster',"id='".$GetPendIndent['requition_by']."'",'emp_name').'</span>'; ?>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
	<?php 
        $GetPendIndent['Reqno']=$s->GetFieldValue('materialrequisitions',"requisitionno='".$reqMainID."'",'Reqno');
        echo 'Requisition No.: <span class="inner">'.$GetPendIndent['Reqno'].'</span>'; ?>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
	<?php 
        $GetPendIndent['prdate']=$s->GetFieldValue('materialrequisitions',"requisitionno='".$reqMainID."'",'prdate');
        echo 'Date: <span class="inner">'.ConvertSQLDate($GetPendIndent['prdate']).'</span>'; ?>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
        <?php 
        $get_opening_date=$s->GetFieldValue('indentpr_mapping',"id='".$_REQUEST['indentID']."'",'openingDate');
        echo 'Quote Opening Date: <span class="inner">'.ConvertSQLDate($get_opening_date).'</span>'; ?>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
         <?php 
        $get_posting_date=$s->GetFieldValue('indentpr_mapping',"id='".$_REQUEST['indentID']."'",'postingDate');
        echo 'Quote Posting Date: <span class="inner">'.ConvertSQLDate($get_posting_date).'</span>'; ?>
        </td>	
</tr>


<?php 
$ItemQuery="select c.id as detailsID,c.mst_itemid as itemId, b.app_quantity as qty ,uom FROM pr_head_approval b 
 inner join requisitionorderdetails c on b.requiNo=c.id inner join materialrequisitions a on a.requisitionno=c.requsitionno
  where b.sr_no='".$maximAss."' and a.requisitionno='".$reqMainID."' and (c.mapped_vendor_status =0 || c.mapped_vendor_status =1) 
  ";
$ItemQueryExec=DB_query($ItemQuery,$db);
$p=1;
  while($itemRow=DB_fetch_array($ItemQueryExec)){
       //echo $itemRow['detailsID'];
       if (in_array($itemRow['detailsID'], $reqDetIdArray))
  {
  $sign='checked';
  }
else
  {
  $sign='';
  }
    $itemCode=$s->GetFieldValue('item_master','id="'.$itemRow['itemId'].'"','StockID'); 
    $itemName=$s->GetFieldValue('item_master','id="'.$itemRow['itemId'].'"','item_name'); 
    $UNITid=$itemRow['uom']; 
    $unitName=$s->GetFieldValue('unitsofmeasure','unitid="'.$UNITid.'"','unitname');
   
      ?>
<input type="hidden" name="mst_itemid[]" id="mst_itemid_<?php echo $k; ?>" value="<?php echo $itemRow['itemId']; ?>"/>
<input type="hidden" name="ApproveQty_By_PurchaseHead[]" id="ApproveQty_By_PurchaseHead_<?php echo $k; ?>" value="<?php echo $itemRow['qty']; ?>"/>
<tr bgcolor="#fff">
    <td><?php echo $p.'. '; ?></td>
    <td><?php echo $itemCode; ?></td>
    <td><?php echo $itemName; ?></td>
    <td><?php echo $unitName; ?></td>
    <td><?php echo $itemRow['qty']; ?></td>
    <td><input type="checkbox" name="requiDetId[<?php echo $k; ?>]" id="requiDetId_<?php echo $k; ?>" value="<?php echo $itemRow['detailsID'];?>" <?php echo $sign; ?>></td>
</tr>
<?php $p++;$k++;} ?>

<tr>
    <td colspan="6"></td>
</tr>

            <?php   }  ?>
<input type="hidden" id="count" value="<?php echo $k; ?>" />
</table>
<p style="text-align: center"><input type="button" name="mapvendoredit" id="mapvendoredit_<?php echo $k; ?>" value="Map Vendor"  class="search" /></p>