<?php
$PageSecurity = 2;
ob_start();
include('includes/DefinePOClass.php');
$title = _('View Material Receipt Note');
$time = date('G:ia');
$date = date($_SESSION['DefaultDateFormat']);
if(isset($_GET['mrnid']) && $_GET['ViewingOnly']==1)
{
	   $sql = "SELECT * From dbl_addmrn Where `id`='".$_GET['mrnid']."'";
	$result = DB_query($sql, $db);
	$myrow = DB_fetch_array($result);
	//echo "<pre>";
	//print_r($myrow);
}
$url_cancel= "index.php?route=DealerDistrbutions/Inventory/transation/material_receipt_note_index".$rurl;
$url_add= "index.php?route=DealerDistrbutions/Inventory/transation/material_receipt_note_view".$rurl;
?>

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

<h3>Material Receipt Note</h3>
<h4 style="text-align:left; padding-left:10px;">GENERAL DETAILS</h4>


<table width="100%" border="1" cellspacing="0" cellpadding="3">
  <tr>
    <th><strong>Mrn No. </strong></th>
    <td colspan="2"><?php echo $myrow['MRNNo'];?></td>
    <th ><strong>MRN Date </strong></th>
    <td colspan="2"><?php echo ConvertSQLDate($myrow['MRNDate']);?></td>
  </tr>
  <tr>
  <th><strong>Dealer<font color="#FF0000">*</font></strong></th>
    <td colspan="2"><?php echo $s->getField('dbl_dealer','id',$myrow['site'],'dealer_name');	?></td>
	 <th><strong>Store </strong></th>
   <td colspan="2"><?php echo $s->getField('dbl_dealer_store','dealer',$myrow['site'],'dealer_store_name');	?></td>
      </tr>
   
  <tr>
	 <th><strong>Received Against</strong></th>
    <td colspan="2"><?php 
	if($myrow['ReceivedAgainst']=='PO')
	{echo "Purchase Order";}
	else if($myrow['ReceivedAgainst']=='APCM')
	{echo "PC Material";}
	else if($myrow['ReceivedAgainst']=='ACM')
	{echo "Client Material";}
	else if($myrow['ReceivedAgainst']=='AMSR')
	{echo "Material Shifting Record";}
	else echo $myrow['ReceivedAgainst'];?></td>
	
	<th><strong>Recevied From </strong></th>
    <td colspan="2"><?php echo $s->getField('locations','loccode',$myrow['ReceivedFrom'],'locationname'); 
       ?></td>
  </tr>
  <tr>
    <th><strong><?php if($myrow['ReceivedAgainst']=='PO'){ ?>PO/Challan/WO/ Ref.No.M<?php } else {?>Against<?php } ?></strong></th>
    <td colspan="2"><?php 
		if($myrow['ReceivedAgainst']=='PO'){
		$po_sql=DB_query("Select PO_Orderno from purchorders where orderno='".$myrow['PO_WO_MTO']."'",$db);
		$po_row=DB_fetch_array($po_sql);
		echo $po_row['PO_Orderno'];}
		elseif($myrow['req_no']!='' | $myrow['req_no']!='0')
		{
			$req_sql=DB_query("Select Reqno from materialrequisitions where requisitionno='".$myrow['req_no']."'",$db);
			$req_row=DB_fetch_array($req_sql);
			echo $req_row['Reqno'];
		}
		else{echo "Direct";}
	     ?></td>
    <th><strong>Order Date </strong></th>
    <td colspan="2"><?php echo ConvertSQLDate($myrow['OrderDate']);?></td>
  </tr>
    <tr>
    <th><strong>Document Type</strong></th>
    <td colspan="2"><?php echo $myrow['DocumentType'];?></td>
    <th><strong>Document No.</strong></th>
    <td colspan="2"><?php echo $myrow['BillNo'];?></td>
  </tr>
  
    <tr>
    <th><strong>Challan / Bill Date</strong></th>
    <td colspan="2"><?php echo ConvertSQLDate($myrow['MRNVoucherDate']);?></td>
    <th><strong>Gate Entry no</strong></th>
    <td colspan="2"><?php echo $myrow['GetPassNo'];?></td>
  </tr>
    <tr>
    <th><strong>Transporter Name</strong></th>
    <td colspan="2"><?php echo $myrow['Transp_name'];?></td>
    <th><strong>Vehicle No.</strong></th>
    <td colspan="2"><?php echo $myrow['VehicleNo'];?></td>
  </tr>
    <tr>
    <th><strong>In Time</strong></th>
    <td colspan="2"><?php echo $myrow['TimeIn'];?></p></td>
    <th><strong>L R No.</strong></th>
    <td colspan="2"><?php echo $myrow['LRno'];?></td>
  </tr>
    <tr>
    <th><strong>L R Date</strong></th>
    <td colspan="2"><?php echo ConvertSQLDate($myrow['LRdate']);?></td>
    <th><strong>Form Type </strong></th>
    <td colspan="2"><?php echo $myrow['form_type']; ?></td>
  </tr>
    <tr>
    <th><strong>Form No</strong></th>
    <td colspan="2"><?php echo $myrow['form_no']; ?></td>
    <th>Gate Pass Date </th>
    <td colspan="2"><?php echo ConvertSQLDate($myrow['gatepassdate']); ?></td>
  </tr>
  <tr>
    <th><strong>Work Order No</strong></th>
    <td colspan="2"><?php echo $s->getField('salesorder','id',$myrow['workorderno'],'orderno'); ?></td>
    <th>Work Order Item </th>
    <td colspan="2"><?php echo $s->getField('item_master','id',$myrow['workorderitem'],'item_name'); ?></td>
  </tr>
    <tr>
    <th><strong>Remarks If Any</strong></th>
    <td colspan="5"><?php echo $myrow['RemarksIfAny'];?></td>
  </tr>
</table>


<br />
<?php 
  $sqlQty = "SELECT * From dbl_addmrnqty Where issue_id='".$_GET['mrnid']."'";
	$Qty_result = DB_query($sqlQty, $db);
	
	//echo "<pre>";
	//print_r($Qty_result);
?>
<h4 style="text-align:left; padding-left:10px;">ITEM DETAILS</h4>

<div style="overflow:auto; width:800px ;"   >
<table width="700px;" border="1" cellspacing="1" cellpadding="2">
  <tr>
       <th><strong>S. NO.</strong></th>
       <th><strong>ITEM CODE </strong></th>
       <th><strong>DESCRIPTION</strong></th>
       <th><strong> UOM</strong></th>
	   <?php if($myrow['ReceivedAgainst']=='PO'){?>
       <th><strong>PO QTY </strong></th><?php } ?>
       <th><strong>QTY AS PER BILL </strong></th>
       <th><strong>QTY RECEIVED</strong></th>
	    <th><strong>SHORT QUANTITY </strong></th>
       <th><strong>RATE</strong></th>
       <th><strong>TOTAL ITEM PRICE</strong></th>
	   
  </tr>
<?php 
$x=0;
while($myrow2 = DB_fetch_array($Qty_result)) 
{
    $ql_purch_details=DB_query("select * from purchorderdetails where orderno='".$myrow['ReceivedFrom']."'",$db);
	$Purch_Sql=DB_query("Select * from purchorders where orderno='".$myrow2['order_no']."'",$db);
	$Purch_Row=DB_fetch_array( $Purch_Sql);
	$record=DB_query("select * from item_master where StockID='".$myrow2['itemcode']."' || id='".$myrow2['mst_itemid']."'",$db);
	$record_row=DB_fetch_array($record);
	
	
?>  
<tr>
<td><?php echo $x+1; ?></td>
<td><?php echo $record_row['StockID']; ?></td>
<td><?php echo $record_row['item_name']; ?></td>
<td><?php $unit=$s->getField('unitsofmeasure','unitid',$record_row['conv_unit'],'unitname');
echo $unit; ?></td>
<?php if($myrow['ReceivedAgainst']=='PO'){?>
<td><?php echo $myrow2['POQty']; ?></td><?php } ?>
<td><?php echo $myrow2['qty_as_per_bill']; ?></td>
<td><?php echo $myrow2['reciveqty']; ?></td>
<td><?php echo $myrow2['short_accessid']; ?></td>
<td><?php echo $myrow2['itemprice']; ?></td>
<td><?php echo $myrow2['item_total_rate']; ?></td>

</tr>
<?php $x++; } ?>
</table>
</div>
<div style="clear:both"></div>
<br />
<div style="width:790px;" align="right">			
			
		      <table width="43%" border="1" cellspacing="0" cellpadding="3" bgcolor="#b7b7b7">
                <tr>
                  <td><strong>TOTAL AMOUNT</strong> </td>
                  <td ><input type="text" name="total_item_amount" id="total_item_amount" style="width:100%;" onfocus="cal_totalamount()" value="<?php echo $myrow['total_Item_Amount'];?>"/></td>
               </tr>
              <tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><input type="text" name="pkg_perc" id="pkg_perc" value="<?php echo $myrow['pkg_perc'];?>" size="5" onblur="calcPackaging(this.value)" /><input name="pkg_charges" id="pkg_charges1" type="text" value="<?php echo $myrow['pkg_charges'];?>" size="28" /></td>
                </tr>
                <tr>
                  <td><strong>Vat/Cst(discription) </strong> </td>
                  <?php
				$Taxsql='SELECT salestax_id,tax_code, taxrate FROM sales_tax_master';
				$Taxresult=DB_query($Taxsql,$db);
     	?>
              <td><select id="taxname" name="vat_cst" onchange="tax_rate1(this.value)" style="width:100%;">
	          <option value="0">---Select---</option>
                  <?php 
			while($Taxmyrow=DB_fetch_array($Taxresult)){
			?>
                  <option  value="<?php echo $Taxmyrow['salestax_id']; ?>"<?php echo ($myrow['vat_cst']==$Taxmyrow['salestax_id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>
                  <?php } ?>
              </select></td>
 
              </tr>
              <tr>
              	<td><strong>Tax Value</strong></td>
              <td><div id="taxval">
                  <input type="text" name="taxvalue" id="taxvalue" style="width:100%;" value="<?php echo $myrow['vat_cst_val'];?>" readonly="true"/>
              </div>

	</td>
                   </tr>
                <tr>
                  <td><strong>Surcharge Amount</strong> </td>
                  <td><input type="text" name="sur_oct_per" id="sur_oct_per"  size="10" onchange="calsuroctamt(this.value)" value="<?php echo $myrow['sur_oct_per'];?>"/><input name="sur_oct_amt" type="text" id="sur_oct_amt" value="<?php echo $myrow['sur_oct_amt'];?>" style="width:60%;" /></td>
                </tr>
                <tr>
                  <td><strong>Freight</strong> </td>
                  <td><input type="text" name="tot_freight" id="TotalCharge" style="width:100%;" value="<?php echo $myrow['tot_freight'];?>"/></td>
                </tr>
                
                <tr>
                  <td><strong>Additional Charges</strong> </td>
                  <td><input name="add_charges" id="additionalCharges" type="text" value="<?php echo $myrow['add_charges'];?>" size="25" style="width:100%;" /></td>
                </tr>
				<!--<tr>
					<td><strong>Round Off</strong></td>
					<td><input type="text" name="round_off" id="round_off" style="width:100%;"/></td>
				</tr>-->
				
                <tr>
				<td><strong>Grand Total</strong></td>
                  <td><input type="text" name="grandtotal" id="GrandTotal" onfocus="cal_grandamount()"  size="12" value="<?php echo $myrow['grandtotal'];?>"/><input type="hidden"  id="orig_grand_tot" value="<?php echo $myrow['grandtotal'];?>"/>&nbsp;<strong>Round Off</strong>&nbsp;<select name="round_off" id="round_off" style="width:50px; height:20px" onchange="calcRounded(this.value)">
				  <option value="">None</option>
				  <option value="+" <?php if($myrow['round_off']=='+') echo "selected";?>>+</option>
				  <option value="-" <?php if($myrow['round_off']=='-') echo "selected";?>>-</option>
				  </select></td>
                </tr>
              </table>
		    
</div>



<p align="center"> <a href="index.php?route=Inventory/transation/material_receipt_note_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewReturn=yes"><input type="button" value="Cancel" name="Back" /></a></p>

</div>




<?php 
$mrn_sql="select * from mrn_charges where MRN_id='".$_GET['mrnid']."'";
$mrn_result=DB_query($mrn_sql,$db);
?>