
<?php //error_reporting(0);
include('./includes/fun-php.php');
include('./includes/fun-HRClass.php');
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];

$rurl="index.php?route=HRModule/master_payslip&action=View&modid=".$modid."&frmid=".$frmid."";
 $rurl_view="index.php?route=Print_PaySlipReport&modid=".$modid."&frmid=".$frmid."";
 $frurl_view="index.php?route=HRModule/PaySlipReport&action=View&modid=".$modid."&frmid=".$frmid."";
if($_REQUEST['Search']   )
		{
		$paystatus=true;  
		$_SESSION['payyear']=$_REQUEST['payyear'];
		$_SESSION['paymonth']=$_REQUEST['paymonth'];
		$_SESSION['empcode']=$_REQUEST['empcode'];
		$_SESSION['emptype']=$_REQUEST['emptype'];
		$_SESSION['emp_salprocess_site']=$_REQUEST['site'];
		$years=$_SESSION['payyear'];
		$month=$_SESSION['paymonth'];	   
		$empcode=$_SESSION['empcode'];
		$emptype=$_SESSION['emptype'];
		$emp_salprocess_site=$_SESSION['emp_salprocess_site'];
			
    }	 
     ?>
     <script language="javascript">
	 var th = ['','thousand','million', 'billion','trillion'];
// uncomment this line for English Number System
// var th = ['','thousand','million', 'milliard','billion'];

var dg = ['zero','one','two','three','four', 'five','six','seven','eight','nine']; var tn = ['ten','eleven','twelve','thirteen', 'fourteen','fifteen','sixteen', 'seventeen','eighteen','nineteen']; 

var tw = ['twenty','thirty','forty','fifty', 'sixty','seventy','eighty','ninety']; 

function toWords(s)
{ 

	s = s.toString();
	s = s.replace(/[\, ]/g,''); if (s != parseFloat(s)) return 'not a number'; var x = s.indexOf('.'); if (x == -1) x = s.length; if (x > 15) return 'too big'; var n = s.split(''); var str = ''; var sk = 0; for (var i=0; i < x; i++) {if ((x-i)%3==2) {if (n[i] == '1') {str += tn[Number(n[i+1])] + ' '; i++; sk=1;} else if (n[i]!=0) {str += tw[n[i]-2] + ' ';sk=1;}} else if (n[i]!=0) {str += dg[n[i]] +' '; if ((x-i)%3==0) str += 'hundred ';sk=1;} if ((x-i)%3==1) {if (sk) str += th[(x-i-1)/3] + ' ';sk=0;}} if (x != s.length) {var y = s.length; str += 'point '; for (var i=x+1; i<y; i++) str += dg[n[i]] +' '; str+=' paise';} 
	var xx=str.replace(/\s+/g,' ');
	return(xx);	 
	 
	
	}


function calOTAmt()
{
	
	var addinsal =  document.getElementById("addinsal").value;
	
if(addinsal=='Y'){	
	  var OTBasicAmount = parseInt(document.getElementById("OTBasicAmount").value);	
	  var OThours = parseInt(document.getElementById("OThours").value);	
	  var workingday= parseInt(document.getElementById("workingdays").value);	
	   var Amt=parseInt(OTBasicAmount/workingday);
	   var HourAmt=parseFloat(Amt/8);
	   var ansD = document.getElementById("OTAmount");
	   var calAmt=parseInt(OThours * HourAmt);
	    ansD.value = calAmt;
	    	var ansD1 = document.getElementById("net_earning");
	    	val1=	ansD1.value;
			ansD1.value =parseInt(val1)+ calAmt ;	
			 document.getElementById("netpay").value=parseInt(document.getElementById("netpay").value) + 	calAmt;
			  document.getElementById("wordamt").value=toWords(parseInt(document.getElementById("netpay").value));
}
	 
	 
}

function calEarningOTAmt(j)
{
		var basicsal =  document.getElementById("basicsal").value;
		var C=0; 
		var C1=0;
		for(i=0;i<j;i++)
		{
			var C = parseInt(C)+ parseInt(document.getElementById("allowcode_value_"+i).value);
			var C1 = parseInt(C1)+ parseInt(document.getElementById("allowdeduction_value_"+i).value);		 
		}
		 document.getElementById("net_earning").value=C;
		 document.getElementById("earning").value=C;
		 document.getElementById("deduction").value=C1; 		 	 
		 document.getElementById("netpay").value=C-C1;
	document.getElementById("wordamt").value=toWords(C-C1);
}
 
     function calculation_deduction()
	 {
                var val1 = parseInt(document.getElementById("total_deduction").value);
				var val2 = parseInt(document.getElementById("loan").value);
				var val3 = parseInt(document.getElementById("ptax").value);
				var val4 = parseInt(document.getElementById("advancetax").value);
				
				var ansD = document.getElementById("deduction");							
     			ansD.value = val1 + val2+ val3+ val4;
				
 				var ded = parseInt(document.getElementById("deduction").value);
				var earning = parseInt(document.getElementById("earning").value);
				var ansD1 = document.getElementById("netpay");			
				ansD1.value = earning - ansD.value;	
				document.getElementById("wordamt").value=toWords(ansD1.value);
	 }

/* 
function cal_netpay()
	 {
		var ded = parseInt(document.getElementById("deduction").value);
		var earning = parseInt(document.getElementById("earning").value);
		var ansD = document.getElementById("netpay");			
		ansD.value = earning - ded;	
		document.getElementById("wordamt").value=toWords(ansD1.value);
	}*/
     </script>
     
     



 <h2> 
 <?php echo  $s->getField('companies','CompanyId',$_SESSION['ACGCompanyId'],'CompanyName');  ?>

</h2>
<h3 style="margin:0px; padding:0px; border-bottom:none;"><?php echo $_REQUEST['site']; ?>, <?php echo $s->getField('locations','loccode',$_REQUEST['site'],'locationname'); ?></h3>
<h3>Pruchase Comparative Statement</h3>
<?php
$select1=DB_query("select * from requisitionorderdetails where requsitionno='".$_REQUEST['RequisitionNo']."'",$db);
	while($row1=DB_fetch_array($select1))
	{
	$itemid[]=$row1['mst_itemid'];
}
?>

<div style="width:910px; overflow:auto; margin-left:auto; margin-right:auto;">

	<table border="1" cellpadding="3" cellspacing="0"  width="100%">
	<tr>
		
<td width="17%" bgcolor="#e2e2e2"><strong>Purchase Requiestion No.:</strong></td>
		 

		
		
		
		<td  width="21%"><?php echo $s->getField('materialrequisitions','requisitionno',$_REQUEST['RequisitionNo'],'Reqno'); ?> </td> 
 <td  width="4%" bgcolor="#e2e2e2"><strong>Date:</strong><br />
 
	  </td> 
  <td  width="21%"><?php echo $s->getField('materialrequisitions','requisitionno',$_REQUEST['RequisitionNo'],'prdate'); ?> </td>
   <td width="17%" bgcolor="#e2e2e2"><strong>Date:(Report Printing date)</strong><br />
 
	  </td>
	  <td><?php  echo date('Y-m-d'); ?> </td>       
</tr></table>

  </div>
 <?php
  $dataarray=array();
  $mrn=array();
   $party1=array();
  for($i=0;$i<count($itemid);$i++)
  {

   $addmrn=DB_query("SELECT total_amt_with_tax,val_after_disc,MRNNo,MRNDate
    FROM addmrnqty INNER JOIN addmrn ON addmrn.id=addmrnqty.issue_id 
    WHERE mst_itemid='".$itemid[$i]."' order by MRNDate desc limit 0,1",$db);
	while($addmrndata=DB_fetch_array($addmrn))
	{
	$mrn[]=array('mrnno'=> $addmrndata['MRNNo'], 'basic' => $addmrndata['total_amt_with_tax'],'total' => $addmrndata['val_after_disc'],'MRNDate'=>$addmrndata['MRNDate']);
	}
    $vender_id1=DB_query("select * from venderquotations where mst_requisition_no='".$_REQUEST['RequisitionNo']."' ",$db);
	while($vend1=DB_fetch_array($vender_id1))
	{ 
	//echo "SELECT  sub_total AS basic,total_amount AS total 
    //FROM vendorquotationdetails  WHERE quotation_no='".$vend1['id']."' and mst_productid='".$itemid[$i]."'";
	
   $item1=DB_query("SELECT  sub_total AS basic,total_amount AS total 
    FROM vendorquotationdetails  WHERE quotation_no='".$vend1['id']."' and mst_productid='".$itemid[$i]."'",$db);
   $vender=DB_fetch_array($item1);
  
   $dataarray[]=array('mst_supplierno'=> $vend1['mst_supplierno'], 'basic' => $vender['basic'],'total' => $vender['total'],'quotations'=>$vend1['id']);
  
   }
  } 
 
  foreach ($dataarray as $key => $row1) {
    $volume[$key]  = $row1['basic'];
    $edition[$key] = $row1['quotations'];
	 $edition1[$key] = $row1['mst_supplierno'];
}

array_multisort($volume, $edition1,$edition ,SORT_ASC,$dataarray);
//print_r($dataarray);
for($k=0;$k<count($dataarray);$k++)
{
  if(count($dataarray)>0)
  {
 
    if(!in_array($dataarray[$k]['mst_supplierno'],$party1))
	{
    $party1[]=$dataarray[$k]['mst_supplierno'];
     $vendorid[]=$dataarray[$k]['quotations'];
   
      
  }
  }
  }
 
  ?>
<table cellpadding="0" cellspacing="0" border="1" width="100%">
	<tr><td rowspan="2"  align="left" bgcolor="#b7b7b7"><strong>S.No.</strong></td>
		<td rowspan="2" align="left" bgcolor="#b7b7b7"><strong>Item Code</strong></td>
		<td  rowspan="2" align="left" bgcolor="#b7b7b7" ><strong>Item Name</strong></td>
		<td align="left" style="padding:0px;"><table width="100%%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" bgcolor="#b7b7b7" class="pad" style="border-bottom:#333333 1px solid;"><strong><?php echo $s->getField('suppliers','id',$party1[0],'vendor_name'); ?></strong></td>
  </tr>
  <tr>
    <td align="center" bgcolor="#b7b7b7" class="pad" style="border-bottom:#333333 1px solid;"><strong><?php echo $s->getField('suppliers','id',$party1[0],'vendor_code'); ?></strong></td>
  </tr>
  <tr>
    <td align="center" bgcolor="#b7b7b7" class="pad"><strong><?php echo $s->getField('suppliers','id',$party1[0],'address3'); ?></strong></td>
  </tr>
</table></th>
		<th align="left" style="padding:0px;"><table width="100%%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" style="border-bottom:#333333 1px solid;" class="pad"><strong><?php echo $s->getField('suppliers','id',$party1[1],'vendor_name'); ?></strong></td>
  </tr>
  <tr>
    <td align="center" style="border-bottom:#333333 1px solid;" class="pad"><strong><?php echo $s->getField('suppliers','id',$party1[1],'vendor_code'); ?></strong></td>
  </tr>
  <tr>
    <td align="center" class="pad"><strong><?php echo $s->getField('suppliers','id',$party1[1],'address3'); ?></strong></td>
  </tr>
</table></th>
		<th align="left"><strong>Previous Purchae Rate</strong></th>
	</tr>
	
		<tr bgcolor="#FFFFFF">
		<td rowspan="6" align="left" valign="top"><table width="100%" border="1" cellpadding="0" cellspacing="0"  style="border-top:none; border-left:none; border-right:none; border-bottom:none; border-color:#333333">
  <tr>
    <td width="40%" align="left" valign="top" bgcolor="#b7b7b7" class="pad">Basic</td>
    <td align="left" valign="top" bgcolor="#b7b7b7" class="pad">Landed</td>
  </tr>
  
<?php
  $vendor1=DB_query("select sub_total AS basic,total_amount AS total
   from  vendorquotationdetails where quotation_no='".$vendorid[0]."'",$db);
  while($vendor1_row=DB_fetch_array($vendor1))
  {
  
?>
  <tr>
    <td align="left" valign="top" class="pad"><?php echo $vendor1_row['basic']; ?></td>
    <td align="left" valign="top" class="pad"><?php echo $vendor1_row['total']; ?></td>
  </tr>
  <?php  } ?>
</table></td>
		<td rowspan="6" align="left" valign="top"><table width="100%" border="1" cellpadding="0" cellspacing="0"  style="border-top:none; border-left:none; border-right:none; border-bottom:none; border-color:#333333">
  <tr>
    <td width="40%" align="left" valign="top" bgcolor="#b7b7b7" class="pad">Basic</td>
    <td align="left" valign="top" bgcolor="#b7b7b7" class="pad">Landed</td>
  </tr>
  <?php
 
  $vendor21=DB_query("select sub_total AS basic,total_amount AS total
   from  vendorquotationdetails where quotation_no='".$vendorid[1]."'",$db);
  while($vendor2_row=DB_fetch_array($vendor21))
  {
  
?>
  <tr>
    <td align="left" valign="top" class="pad"><?php echo $vendor2_row['basic']; ?></td>
    <td align="left" valign="top" class="pad"><?php echo $vendor2_row['total']; ?></td>
  </tr>
  <?php  } ?>
</table></td>
		<td rowspan="6" align="left" valign="top"><table width="100%" border="1" cellpadding="0" cellspacing="0"  style="border-top:none; border-left:none; border-right:none; border-bottom:none; border-color:#333333">
  <tr>
    <td width="22%" align="left" valign="top" bgcolor="#b7b7b7" class="pad">Basic</td>
    <td width="21%" align="left" valign="top" bgcolor="#b7b7b7" class="pad">Landed</td>
    <td width="45%" align="left" valign="top" bgcolor="#b7b7b7" class="pad">MRN No.</td>
    <td width="12%" align="left" valign="top" bgcolor="#b7b7b7" class="pad">MRN Date</td>
  </tr>
 <?php 
 
 foreach($mrn as $key => $row4)
 {
 ?>
  
  <tr>
    <td align="left" valign="top" class="pad"><?php echo $row4['basic']; ?></td>
    <td align="left" valign="top" class="pad"><?php echo  $row4['total'];?></td>
    <td align="left" valign="top" class="pad"><?php  echo  $row4['mrnno'];?></td>
    <td align="left" valign="top" class="pad"><?php echo  $row4['MRNDate']; ?></td>
  </tr>
 <?php } ?>
</table></td>
<?php
$i=1;
    $select=DB_query("select * from requisitionorderdetails where requsitionno='".$_REQUEST['RequisitionNo']."'",$db);
	while($row=DB_fetch_array($select))
	{
	

 ?>
	<tr bgcolor="#FFFFFF">
		<td class="pad"><?php echo $i; ?></td>
		<td class="pad"><?php echo $s->getField('item_master','id',$row['mst_itemid'],'StockID'); ?></td>
		<td class="pad"><?php echo $s->getField('item_master','id',$row['mst_itemid'],'item_name'); ?></td>
		</tr>
		<?php $i++; } ?>
	
</table>

 <table width="100%%"  cellpadding="3" cellspacing="0" border="1">
  <tr>
    <td width="38%" bgcolor="#e2e2e2"><strong>Quotion No. and Date</strong></td>
    <td width="14%"><?php echo $s->getField('venderquotations','id',$vendorid[0],'vernder_quotation');?></td>
    <td width="15%"><?php echo $s->getField('venderquotations','id',$vendorid[1],'vernder_quotation');?></td>
    <td colspan="2" align="center" bgcolor="#b7b7b7" style="text-align:center;"><strong>Action Recommended</strong></td>
   </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Discount</strong></td>
    <td><?php
	$discount=DB_query("select sum(discount_amount) as dis ,sum(specialdiscount_amount) as spdis
	 from vendorquotationdetails where quotation_no='".$vendorid[0]."'",$db);
	$discountamt=DB_fetch_array($discount);
	echo ($discountamt['dis']+$discountamt['spdis']); 
	 
	?>
	</td>
    <td><?php
	$discount1=DB_query("select sum(discount_amount) as dis ,sum(specialdiscount_amount) as spdis
	 from vendorquotationdetails where quotation_no='".$vendorid[1]."'",$db);
	$discountamt1=DB_fetch_array($discount1);
	echo ($discountamt1['dis']+$discountamt1['spdis']); 
	 
	?></td>
    <td>a)  Place Order on</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Packing Charges</strong></td>
    <td><?php echo $s->getField('venderquotations','id',$vendorid[0],'pkg_charges');	?></td>
    <td><?php echo $s->getField('venderquotations','id',$vendorid[1],'pkg_charges');	?></td>
    <td>b) Negotiated with</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Excise Duty+Cess</strong></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>c) Order No./ Date</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>VAT/CST + Surcharge</strong></td>
   <td><?php echo $s->getField('venderquotations','id',$vendorid[0],'vat_cst_amount');	?></td>
    <td><?php echo $s->getField('venderquotations','id',$vendorid[1],'vat_cst_amount');	?></td>

    <td>   P.O. No. </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Insurance</strong></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td> Date:</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Forwarding</strong></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><table width="100%%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="50%">Prepared by  </td>
    <td>Checked by</td>
    </tr>
</table></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Freight</strong></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Other Charges</strong></td>
     <td><?php echo $s->getField('venderquotations','id',$vendorid[0],'totalcharge');	?></td>
    <td><?php echo $s->getField('venderquotations','id',$vendorid[1],'totalcharge');	?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Payment Terms</strong></td>
     <td><?php echo $s->getField('venderquotations','id',$vendorid[0],'payment_term');	?> Days</td>
    <td><?php echo $s->getField('venderquotations','id',$vendorid[1],'payment_term');	?> Days</td>
    <td>&nbsp;</td>
    <td>Approved By</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Delivery Status</strong></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  
  <tr>
    <td bgcolor="#e2e2e2"><strong>Remarks</strong></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

