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

//$SQLVenQuo=DB_Query("SELECT * FROM indentpr_mapping where  CompanyId='".$_SESSION['ACGCompanyId']."' group by indentPrno",$db); 
if($_SESSION['vendorid'])
{
 $indentQry="SELECT * FROM indentpr_mapping where  CompanyId='".$_SESSION['ACGCompanyId']."'
  and (quotaion_status='0' || quotaion_status='2') and FIND_IN_SET( '".$_SESSION['vendorid']."', mapped_vendor ) and createdDate  between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."' and site in('".$_SESSION['AssignedBranch']."')";
}
 else {
    $indentQry="SELECT * FROM indentpr_mapping where  CompanyId='".$_SESSION['ACGCompanyId']."' 
    and (quotaion_status='0' || quotaion_status='2') and createdDate  between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."' and site in('".$_SESSION['AssignedBranch']."')";
}
 //echo $indentQry;
$SQLVenQuo=DB_Query($indentQry,$db); 

?>

<!-- <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>
  <ul class="nav nav-tabs fl-lft">
      <li role="presentation" class="active"><a href="#pending" aria-controls="pending" role="tab" data-toggle="tab">Pending</a></li>
      <li role="presentation"><a href="#quotations" aria-controls="quotations" role="tab" data-toggle="tab">Quotations</a></li>
  </ul>

<div class="tab-content visits">
    <div role="tabpanel" class="tab-pane active" id="pending">
      <table border="0" cellpadding="3" cellspacing="0" width="100%" class="thborder">
      <tr>
        <th width="4%" rowspan="2">S. No.</th>
        <th width="12%" rowspan="2">RFQ NO. No.</th>
        <th width="8%" rowspan="2">RFQ Date</th>
        <th width="10%" rowspan="2">Against Requisitions</th>
        <th width="9%" rowspan="2">Requisitions Date</th>
        <th width="9%" rowspan="2">Posting Date</th>
             <!-- <th rowspan="2">Items</th>
              <th rowspan="2">Qty.</th>-->
        <th rowspan="2">Type</th>
        <th width="8%" rowspan="2">No. of Quotations</th>
        <th colspan="2" style="text-align: center;">Action</th>
      </tr>
      <tr>
        <th width="6%" style="text-align: center;">Status<!--Vendor Quotation--></th>
        <?php if($_SESSION['frmView']==1){?><th width="5%" style="text-align: center;">View</th><?php } ?>  
      </tr>
      <?php 
      if(DB_num_rows($SQLVenQuo)>0){
      $i=0; while($QuotDetails=DB_fetch_array($SQLVenQuo)){
      ?>
      <tr bgcolor="#fff">
        <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 echo ConvertSQLDate($QuotDetails['postingDate']); ?></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>
                  <?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;">  
        <?php $date1=date('Y-m-d');
                  $date2=$QuotDetails['postingDate'];
                  //if(strtotime($date1) <= strtotime($date2))
                  //{ 
                    ?>
        <a href="index.php?route=POModule/VenderQutations_gst&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&RequisitionNo=<?php echo $PrIndentData['requisitionno']; ?>&mapid=<?php echo $QuotDetails['id']; ?>"><input type="button" value="Pending" class="search" /></a>
          <?php //}else{?>
        <!-- <input type="button" value="Pending" title="Not Allowed" class="search" />   -->
        <?php //} ?>  
        </td>        
        <?php if($_SESSION['frmView']==1){?><td style="text-align: center;"><a href="index.php?route=POModule/mapped_indent_view_gst&modid=<?php echo $_REQUEST['modid']?>&frmid=<?php echo $_REQUEST['frmid']?>&mapid=<?php echo $QuotDetails['id']; ?>"><img src="images/search.gif" width="15" height="15" title="View" /></a></td><?php } ?>  
        </tr>
      <?php $i++;} }else{?>
      <tr bgcolor="#fff">
        <td colspan="11" style="color:red;">No Record Found !! </td>
      </tr>
      <?php } ?>
      </table>
    </div>
    <div role="tabpanel" class="tab-pane" id="quotations">
<!-- <h3>Quotations</h3> -->
      <table width="100%" border="0" cellpadding="3" cellspacing="0" >
        <tr>
          <td width="6%">
              <div style="width:25px;height: 25px;background-color:#f0f0f0;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:#94e6de;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="0" cellpadding="3" cellspacing="0" width="100%" class="thborder">
      <tr>
        <th width="4%">S.No.</th>
        <th width="12%">Quotation No.</th>
        <th width="10%">Quotation Date</th>
        <th width="10%">Party Quotation No.</th>
        <th width="10%">Party Quotation Date</th>
        <th width="10%">Against Requisitions</th>
        <th width="10%">Grand Total</th>
        <th>Vendors</th>
        <th width="8%" style="text-align:center;">Action</th>        
      </tr>
      <?php 
      if($_SESSION['UserType']=="SuperAdmin")
      {
      $quotationQry="SELECT * FROM venderquotations where  CompanyId='".$_SESSION['ACGCompanyId']."' and Quotation_Date  between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."' and Site in('".$_SESSION['AssignedBranch']."')";
      }
      else
      {
      $quotationQry="SELECT * FROM venderquotations where  CompanyId='".$_SESSION['ACGCompanyId']."' 
      and createdBy='".trim($_SESSION['UserID'])."' and Quotation_Date  between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."' and Site in('".$_SESSION['AssignedBranch']."')";
      }

      $quotationQryExec=DB_Query($quotationQry,$db);
      $j=0;
      if(DB_num_rows($quotationQryExec)>0){
       while($QuotDetails=DB_fetch_array($quotationQryExec)){
           $quoStatus=$s->GetFieldValue('indentpr_mapping',"id='".$QuotDetails['mapid']."'",'quotaion_status');
           if($quoStatus=='0' || $quoStatus=='2'){ $color='#f0f0f0'; }
           else { $color='#94e6de'; }
           $category=$s->GetFieldValue('materialrequisitions',"requisitionno='".$QuotDetails['mapid']."'",'category');

           //Count whether po has been made or not against this quotation

          /*  $sql_count_po="select count(*) from purchorders where quotationId='".$QuotDetails['id']."'";
           $result_count_po=DB_query($sql_count_po,$db);
           $rs_count_po=DB_fetch_array($result_count_po);
           $count_po=$rs_count_po[0]; */

           //Count whether comparison has been made or not against this quotation

         /*   $sql_count_po="select count(*) from venderquotations where quotationId='".$QuotDetails['id']."'";
           $result_count_po=DB_query($sql_count_po,$db);
           $rs_count_po=DB_fetch_array($result_count_po);
           $count_po=$rs_count_po[0]; */
      ?>
      <tr bgcolor="<?php echo $color; ?>">
          <td ><?php echo ($j+1).'.';?></td>
          <td ><?php echo $QuotDetails['quotation_no']; ?></td>
          <td ><?php echo ConvertSQLDate($QuotDetails['Quotation_Date']); ?></td>
          <td ><?php echo $QuotDetails['party_Quo_no']; ?></td>
          <td ><?php echo ConvertSQLDate($QuotDetails['party_Quo_date']); ?></td>
          <td ><?php echo $s->GetFieldValue('indentpr_mapping',"id='".$QuotDetails['mapid']."'",'mapNo'); ?></td>
          <td ><?php echo $QuotDetails['grand_total']; ?></td>
          <td ><?php $mapedVendorsid=$s->GetFieldValue('indentpr_mapping',"id='".$QuotDetails['mapid']."'",'mapped_vendor');    
                echo $s->GetFieldValue('suppliers',"id='".$QuotDetails['mst_supplierno']."'",'vendor_name').'<br/>'; 
             ?>
          </td>
          <td style="text-align:center;">
             <?php if($_SESSION['frmEdit']=='1' && $QuotDetails['com_status']!='1'){?>
                 <a href="index.php?route=POModule/VenderQutationsEdit_gst&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=Edit&id=<?php echo $QuotDetails['id']; ?>" ><img src="images/icon-edit.png" height="15" width="15" title="Edit" /></a>
                 <?php /*} else if($category=='Service') { echo "Service Type"; */  } else{ ?><img src="images/icon-edit.png" height="15" width="15" title="No Permission" style="opacity:0.5;" /><?php } ?>
          </td>
      </tr>
      <?php $j++;}
      } else { ?>
      <tr>
        <td colspan="9" style="color:red;">No Record Found !! </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>