<?php
	//Start session
	session_start();
	error_reporting(E_ALL ^ E_NOTICE ^E_WARNING);
	//Check whether the session variable SESS_MEMBER_ID is present or not
	if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) {
		header("location: index.php");
		exit();
	}
	if(isset($_SESSION['SESS_DEPT'])&&$_SESSION['SESS_DEPT']!='ACCOUNTS')
	{
		$styleHide = "display:none";
		$style= "style='display:none'";
	}
?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<head>
<title>CERDIT NOTE ENTRY</title>
<meta name="description" content=""/>
<meta name="keywords" content=""/>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<script type="text/javascript" src="../../javascript/jquery.js"></script>
<script type="text/javascript" src="../../javascript/credit_entry_rel.js"></script>
<script type="text/javascript" src="../../javascript/jquery.autocomplete.js"></script>
<script type="text/javascript" src="../../javascript/numbertowords.js" ></script>
<script type="text/javascript" src="../../javascript/jquery.datepick.min.js"></script>
<script type="text/javascript" src="../../javascript/jNotify.jquery.min.js"></script>
<script type="text/javascript" src="../../javascript/jNotify.jquery.js"></script>

<link rel="stylesheet" href="../../css/jNotify.jquery.css">
<link rel="stylesheet" href="../../css/redmond.datepick.css">
<link rel="stylesheet" href="../../css/jquery.autocomplete.css" type="text/css" >
</link>
<link rel="stylesheet" href="../../css/style.css"  type="text/css">
</link>

<link rel="stylesheet" type="text/css" href="../../javascript/tooltip/css/tooltipster.bundle.min.css" />

    <script type="text/javascript" src="../../javascript/tooltip/js/tooltipster.bundle.min.js"></script>

<script type="text/javascript">
function myFunction()
{
jSuccess("Module not available in demo version");
}
</script>
<style type="text/css">

input[type=text],textarea{
	width:100%
}

</style>
</head>

<body >
<table style="display:none">
<tr id="prototype"><td style='display:none'><textarea style='height: 32px;' name='entryid_pv[]' class='entryid_pv'></textarea></td><td></td><td><textarea style='height: 32px;' name='size_pv[]' class='size_pv'></textarea></td><td><textarea style='height: 32px;' name='prodname_pv[]' class='prodname_pv'></textarea></td><td><textarea style='height: 32px;' name='price_pv[]' class='price_pv'></textarea></td><td><textarea style='height: 32px;' name='mrp_pv[]' class='mrp_pv'></textarea></td><td><textarea style='height: 32px;' name='qnty_pv[]' class='qnty_pv'></textarea></td><td><textarea style='height: 32px;' name='fresh_pv[]' class='fresh_pv'></textarea></td><td><textarea style='height: 32px;' name='reprocess_pv[]' class='reprocess_pv'></textarea></td><td><textarea style='height: 32px;' name='demage_pv[]' class='demage_pv'></textarea></td></tr></table>

<div id="pendingRawMatList" class="pendingRawMatList">
<div style=" background-color:white; height:0px;overflow-y: auto;" class="dataDiv dataTableContainer" > </div>

<div class="dragDown">Pending Reciept</div >

</div>

<div id="pendingQuanList" class="pendingQuanList" >
<div style=" background-color:white; height:0px;overflow-y: auto;" class="dataDiv dataTableContainer" > </div>

<!--<div><input type="button" id="calculateqty" value="Calculate"  /></div>
--></div>

<input  id="inline_edit" type="hidden" value="0"  />
<!--<div id="transperent" >
</div>-->
		
        
      <?php 
	    
		
  include '../../db_connect.php';

$orderid= $_GET['orderid'];
$table='';
if(($result = mysqli_query($con,"SELECT * FROM drcrnotereg  where orderid='$orderid'"))&&(!empty($orderid)))
{
	$totpcost=0;
	$totscost=0;
$row = mysqli_fetch_array($result);
if($result = mysqli_query($con,"SELECT * FROM commst  where compid='$row[buyercode]'  "))
$client_detrow = mysqli_fetch_array($result);

if($agentcoderesult = mysqli_query($con,"SELECT * FROM commst  where compid='$row[agentcode]'   "))
$agentcoderow = mysqli_fetch_array($agentcoderesult);

if($distrresult = mysqli_query($con,"SELECT * FROM commst  where compid='$row[distr]'  "))
$distrcoderow = mysqli_fetch_array($distrresult);


if(($result_det = mysqli_query($con,"SELECT * FROM drcrnoteregdet  where orderid='$orderid' order by srno"))&&(!empty($orderid))){
	
		$pcdArray = $_SESSION['SESS_PCD'];
		$table="<div id='form_bookdetails'><table width='100%' id='msview'  cellpadding='0' cellspacing='0' style='table-layout: fixed;
width: 98.7%;'>
		<thead>
			<tr>
            <th width='5%'>Sr No.</th>
			<th width='10%'>$pcdArray[STYLECODE]</th>
			<th style='height: 32px;' width='10%'>$pcdArray[CAT]</th>
			<th style='height: 32px;' width='10%'>$pcdArray[COLOR]</th>
			<th style='height: 32px;' width='10%'>$pcdArray[DESC]</th>			
			<th style='height: 32px;' width='5%'>$pcdArray[SIZESETCODE]</th>			
			<th style='height: 32px;' width='5%'>$pcdArray[SETS]</th>
			<th style='height: 32px;' width='5%'>Qty</th>
			<th style='height: 32px;' width='5%'>MRP</th>
			<th style='height: 32px;$styleHide' width='5%' >WSP</th>
			<th style='height: 32px;$styleHide' width='5%' >Amount</th>
			<th style='height: 32px;' width='5%'></th>
			<th style='height: 32px;' width='5%'></th>
			</tr>
			</thead><tbody>";
while($row_det = mysqli_fetch_array($result_det)){
			$totpcost+=$row_det['pcost'];
			$totscost+=$row_det['scost'];
			$totpamt+=$row_det['pamt'];
			$qty+=$row_det['qty'];
			$sr_track=$row_det['srno'];
			$table.="<tr>
			
			<td style='display:none'><textarea name='entryid'>$row_det[entryid]</textarea></td>
			<td style='display:none'><textarea name='orderid'>$row_det[orderid]</textarea></td>
			<td style='display:none'><textarea name='frm' class='frm'>$row_det[frmdetail]</textarea></td>
			<td width='5%'><textarea name='srno'>$row_det[srno]</textarea></td>
			<td width='10%'><textarea name='prodcode' class='prodcode'>$row_det[prodcode]</textarea></td>
			<td width='10%'><textarea style='height: 32px; ' name='cat' class='cat'>$row_det[cat]</textarea></td>
			<td width='10%'><textarea style='height: 32px;' name='colorcode'>$row_det[colorcode]</textarea></td>
			<td width='10%'><textarea style='height: 32px;' name='shortdesc' class='shortdesc'>$row_det[shortdesc]</textarea></td>
			<td width='5%'><textarea style='height: 32px;' name='sizeset' sizeChartId='$row_det[entryid]' class='sizeset' readonly title='Please double click to see size chart'>$row_det[sizeset]</textarea></td>
			<td width='5%'><textarea  style='height: 32px;' name='set' class='set' >$row_det[set]</textarea></td>
			<td width='5%'><textarea style='height: 32px;' name='qty' class='qty' >$row_det[qty]</textarea></td>	
			<td width='5%'><textarea style='height: 32px;' name='mrp' class='mrp' >$row_det[mrp]</textarea></td>		
			<td width='5%' $style><textarea style='height: 32px;' name='rate' class='rate'>$row_det[pcost]</textarea></td>
			<td width='5%' $style><textarea style='height: 32px;' name='amount' class='amount'>$row_det[pamt]</textarea></td>
			<td width='5%'><input type='button' value='SAVE' class='edit filter_table' style='display:none'/></td>
			<td width='5%'><input type='button' class='deletedet  filter_table' value='X' /></td>
			</tr>";
			
			
			$sizeset_spilt = explode(",",$row_det['sizeset']);
			
			
			
			
			$sql = "SELECT * FROM drcrnotevar  where `job_id` = '$orderid' and `prodname` = '$row_det[prodcode]' and `srno` =  '$sr_track'  order by entryid";
			
			//echo $sql;
			
	if(($prodvar_data1 = mysqli_query($con,$sql))){
			$trow ='';
			$index=1;
			while($prodvar1_row = mysqli_fetch_array($prodvar_data1)){
				
				if($row['rtvalue']!=''||$row['rtvalue']>0){
				$wsp = round($prodvar1_row[mrp]*($row['rtvalue']/100));
				$wspamt = $prodvar1_row[mrp]-$wsp;
				}
				else{
					$wspamt = $prodvar1_row[mrp];
					}
				
				$trow.= "<tr>
				<td style='display:none'><textarea style='height: 32px;' name='entryid_pv[]' class='entryid_pv'>$prodvar1_row[entryid]</textarea></td>
				<td>".($index++)."</td>
				<td><textarea style='height: 32px;' name='prodname_pv[]' class='prodname_pv'>$prodvar1_row[prodname]</textarea></td>
				<td><textarea style='height: 32px;' name='size_pv[]' class='size_pv'>$prodvar1_row[size]</textarea></td>
				<td><textarea style='height: 32px;' name='price_pv[]' class='price_pv'>$wspamt</textarea></td>
				<td><textarea style='height: 32px;' name='mrp_pv[]' class='mrp_pv'>$prodvar1_row[mrp]</textarea></td>
				<td><textarea style='height: 32px;' name='qnty_pv[]' class='qnty_pv'>$prodvar1_row[qnty]</textarea></td>
				<td><textarea style='height: 32px;' name='fresh_pv[]' class='fresh_pv'>$prodvar1_row[fresh]</textarea></td>
				<td><textarea style='height: 32px;' name='reprocess_pv[]' class='reprocess_pv'>$prodvar1_row[reprocess]</textarea></td>
				<td><textarea style='height: 32px;' name='demage_pv[]' class='demage_pv'>$prodvar1_row[demage]</textarea></td>
				</tr>";
				
				}
			 $trow.= "<tr class='foot'>
				<td style='display:none'><textarea style='height: 32px;' name='tentryid_pv[]' class='tentryid_pv'></textarea></td>
				<td>Total</td>
				<td><textarea style='height: 32px;' name='prodname_pv[]' class='prodname_pv'></textarea></td>
				<td><textarea style='height: 32px;' name='tsize_pv[]' class='tsize_pv'>".($index-1)."</textarea></td>
				<td><textarea style='height: 32px;' name='tprice_pv[]' class='tprice_pv'></textarea></td>
				<td><textarea style='height: 32px;' name='tmrp_pv[]' class='tmrp_pv'></textarea></td>
				<td><textarea style='height: 32px;' name='tqnty_pv[]' class='tqnty_pv'></textarea></td>
				<td><textarea style='height: 32px;' name='tfresh_pv[]' class='tfresh_pv'></textarea></td>
				<td><textarea style='height: 32px;' name='treprocess_pv[]' class='treprocess_pv'></textarea></td>
				<td><textarea style='height: 32px;' name='tdemage_pv[]' class='tdemage_pv'></textarea></td>
				</tr>";
			}
			
	   $sizeTable.= "<div class='sizechartdiv' id='$row_det[entryid]' style='display:none;position:absolute'><div class='closediv'> X </div>
       <table  style='border: 1px solid black;background-color:white' border='1' cellspacing='0'>
  	   	<tr><th>Sr. No.</th><th>Prodname</th><th>Size</th><th>WSP</th><th>Mrp</th><th>Quantity</th><th>Fresh</th><th>Reprocess</th><th>Demage</th></tr>
       	$trow
       </table>
       </div>";
	   
}
$temp=$sr_track+1;
$table.="<tr class='last'>
			
			<td style='display:none'><textarea name='entryid'>$row_det[entryid]</textarea></td>
			<td style='display:none'><textarea name='orderid'>$orderid</textarea></td>
			<td style='display:none'><textarea name='frm' class='frm'></textarea></td>
			<td width='5%'><textarea name='srno' readonly>$temp</textarea></td>
			<td width='10%'><textarea name='prodcode' class='prodcode'></textarea></td>
			<td width='10%'><textarea style='height: 32px; ' name='cat' class='cat'></textarea></td>
			<td width='10%'><textarea style='height: 32px;' name='colorcode' class='colorcode'></textarea></td>
			<td width='10%'><textarea style='height: 32px;' name='shortdesc' class='shortdesc'></textarea></td>
			<td width='5%'><textarea style='height: 32px;' name='sizeset' class='sizeset' sizeChartId='new' readonly></textarea></td>
			<td width='5%'><textarea  style='height: 32px;' name='set' class='set' ></textarea></td>
			<td width='5%'><textarea style='height: 32px;' name='qty' class='qty' ></textarea></td>
			<td width='5%'><textarea style='height: 32px;' name='mrp' class='mrp' ></textarea></td>
			<td width='5%' $style><textarea style='height: 32px;' name='rate' class='rate'></textarea></td>
			<td width='5%' $style><textarea style='height: 32px;' name='amount' class='amount'></textarea></td>
			<td width='5%'><input type='button' value='SAVE' class='addnew filter_table' style='display:none'/></td>
			<td width='5%'><input type='button' value='' class='' style='display:none'/></td>
			</tr>";
			
			$table.="<tr class='foot'>
			
			<td width='5%'><textarea name='srno' readonly>Total</textarea></td>
			<td width='10%'><textarea name='prodcode' class='prodcode'></textarea></td>
			<td width='10%'><textarea style='height: 32px; ' name='cat' class='cat'></textarea></td>
			<td width='10%'><textarea style='height: 32px;' name='colorcode' class='colorcode'></textarea></td>
			<td width='10%'><textarea style='height: 32px;' name='shortdesc' class='shortdesc'></textarea></td>
			<td width='5%'><textarea style='height: 32px;' name='sizeset' class='sizeset' sizeChartId='new' readonly></textarea></td>
			<td width='5%'><textarea  style='height: 32px;' name='set' class='set' ></textarea></td>
			<td width='5%'><textarea style='height: 32px;' name='qty' class='qty' ></textarea></td>
			<td width='5%'><textarea style='height: 32px;' name='mrp' class='mrp' ></textarea></td>
			<td width='5%' $style><textarea style='height: 32px;' name='rate' class='rate'></textarea></td>
			<td width='5%' $style><textarea style='height: 32px;' name='amount' class='amount'></textarea></td>
			<td width='5%'><input type='button' value='SAVE' class='addnew filter_table' style='display:none'/></td>
			<td width='5%'><input type='button' value='' class='' style='display:none'/></td>
			</tr>";
			
			$sizeTable.= "<div id='new' class='sizechartdiv' style='display:none;position:absolute'><div class='closediv'> X </div>
       <table  style='border: 1px solid black;background-color:white' border='1' cellspacing='0'>
  <tr>
    <th>Sr. No.</th>
	<th>Prodname</th>
    <th>Size</th>
	<th>Price</th>
	<th>Mrp</th>
    <th>Quantity</th>
	<th>Fresh</th>
    <th>Reprocess</th>
    <th>Demage</th>
  </tr>

  </table>
</div>
";
			
			

$table.="</tbody></table></div>".$sizeTable;
}
}
function time_formatc($temp_time)
{
list($hour, $min, $sec) = explode(':', $temp_time);

return "$hour:$min";
}


function date_formatc($temp_date)
{
list($year, $month, $day) = explode('-', $temp_date);
return "$day/$month/$year";
}
?>
      
      
<div class="main">
    <div id="formbox">
        <form id="bookingform" action=""  method="">
         
         <table width="100%" border="0" height="100%" cellspacing="2">
  <tr class="master_detrow">
    <td width="12%" align="left" >Cr Note Id:<span style="color:red; ">*</span></td>
    <td colspan="3"><span style="float:left;width:45%"><input type="text" name="orderid" id="orderid" tabindex="3" readonly  style="width:70%;float:left;" /> Ref No.</span> <span style="float:right;width:48%"><input type="text" name="refno" id="refno" tabindex="17" /></span></td>
    <td width="9%" align="left">&nbsp;</td>
    <td width="12%" align="left">Cr Note Date:</td>
    <td width="15%"><input type="text" autocomplete="off" name="orderdate" id="orderdate" tabindex="13"  /><input type="hidden" name="drcrtype" id="drcrtype" value='Creditnote'  /></td>
    <td width="8%" align="left"></td>
    <td width="14%"></td>
  </tr>
  <tr class="master_detrow">
    <td align="left">Party</td>
    <td colspan="2" align="left"><input type="text" name="buyercode" id="buyercode" tabindex="3"  /></td>
    <td width="17%" align="left"><input type="text" name="buyerma" id="buyerma" tabindex="3"  /></td>
    
    <td align="left"><input type="button" name="guesmas" id="guesmas" class="button" value="+" style="  width: 28px;padding-left: 8px;padding-right: 8px; cursor:pointer; " title="click to add to master" /></td>
    <td align="left">Type</td>
    <td>
    <select name="ordertype" id="ordertype" style="width:100%">
     <option value=""></option>
    <option value="salereturn">Sale Return</option>
     <option value="discount">Discount</option>
    </select></td>
    <td align="left">Rec Date</td>
    <td><input type="text" autocomplete="off" name="dlvdate" id="dlvdate" tabindex="17" /></td>
    </tr>
  <tr class="master_detrow">
    <td align="left">Address:</td>
    <td colspan="3" rowspan="2"  valign="top"><textarea name="adress" style="height: 52px;" rows="2" tabindex="4" id="adress"></textarea></td>
    <td align="left">&nbsp;</td>
    <td align="left">Rate Type</td>
    <td colspan="2"><input type="text" name="ratetype" id="ratetype" tabindex="17" /></td>
  
    <td align="left"><input type="text" name="rtvalue" id="rtvalue"  /></td>
    </tr>
  <tr class="master_detrow">
    <td align="left">&nbsp;</td>
    <td align="left">&nbsp;</td>
    <td align="left">Shipment</td>
    <td align="right"><select type="text" name="shipvia" id="shipvia" style="width:100%">
    <option value=""></option>
    <option value="AIR">AIR</option>
     <option value="TRANSPORT">TRANSPORT</option>
      <option value="SHIP">SHIP</option>
        <option value="COURIER">COURIER</option>
    </select></td>
    <td align="left">Shipping Paid</td>
    <td align="right">
    <select type="text" name="shippingpaid" id="shippingpaid" style="width:100%">
    <option value=""></option>
    <option value="CONSINGNEE">CONSINGNEE</option>
    <option value="BUYER">BUYER</option>
     <option value="SELF">SELF</option>
    </select></td>
    </tr>
  <tr>
    <td align="left">City</td>
    <td><input type="text" name="city" id="city" tabindex="17" /></td>
    <td align="left">Pin</td>
    <td><input type="text" name="pincode" id="pincode" tabindex="15" /></td>
    <td align="right">&nbsp;</td>
    <td align="left">WayBill No.</td>
    <td align="left"><input type="text" name="lrno" id="lrno" /></td>
    <td align="left">Date</td>
    <td align="left"><input autocomplete="off" type="text" name="lrdate" id="lrdate"  /></td>
  </tr>
  <tr>
    <td align="left">Distributor</td>
    <td colspan="2"><input type="text" name="distrcode" id="distrcode" tabindex="17" /></td>
    <td><input type="text" name="distrname" id="distrname" tabindex="17" /></td>
    <td align="left">&nbsp;</td>
    <td align="left">Invoice No.</td>
    <td align="right"><input type="text" name="invno" id="invno" tabindex="17" /></td>
    <td align="left">Invoice Date</td>
    <td align="right"><input autocomplete="off" type="text" name="invdate" id="invdate" tabindex="17" /></td>
    </tr>
  <tr>
    <td align="left">Agent </td>
    <td colspan="2"><input type="text" name="agentcode" id="agentcode" tabindex="17" /></td>
    <td><input type="text" name="agent" id="agent" tabindex="17" /></td>
    <td align="right">&nbsp;</td>
    
  </tr>
  <tr>
    <td align="left">Comm.%</td>
    <td><input type="text" name="comm" id="comm" tabindex="17" /></td>
    <td align="left">On</td>
    <td><input type="text" name="comm_on" id="comm_on" tabindex="17" /></td>
    <td colspan="5" align="right"><input type="button" class="button" id="print" value="PRINT" />
      <input name="Update" type="button" class="Update button" id="Update" value="UPDATE" style="display:none"  />
      <input type="button" class="save button" id="Save" tabindex="30" value="SAVE"  />
      <input type="button" class="button" id="New" value="NEW" />
      <input type="button" class="close button" id="Close" value="CLOSE"  /></td>
  </tr>
  
 
  <tr>
    <td height="70%" colspan="9" align="left" valign="top" ><div class="table_contain" id="jobdet_container" style="height: 100%;overflow-y: auto;">
    
    
    </div></td>
    </tr>
  <tr>
    <td colspan="9" align="left"><table width="100%" border="0">
     <tr>
       <td width="10%" align="left">Notes:</td>
       <td colspan="5" rowspan="2" valign="top"><textarea name="notes" style="height: 64px;" rows="2" id="notes"></textarea>         <table width="100%" border="0">
           <tr>
             <td colspan="2" align="left">&nbsp;</td>
             </tr>
         </table></td>
         <td colspan="2"></td>
       <td align="left" width="10%" <?php echo $style?> >Total Amt:</td>
        <td colspan="2" <?php echo $style?>><input type="text" size="10"  class="tpcost"  name="ptotal" id="ptotal" value="<?php echo $totpamt?>"/></td>
        <!--<td align="left" <?php echo $style?>>Total Cost:</td>
        <td colspan="2" <?php echo $style?>><input type="text" size="10"  name="stotal" id="stotal" class="tscost" value="<?php echo $totscost?>"/></td>-->
     </tr>
     <tr>
        <td  align="left">&nbsp;</td>
        <td colspan="2"></td>
        <td align="left" width="10%" <?php echo $style?>>Discount:</td>
        <td width="4%" <?php echo $style?> ><input type="text" name="pdiscount" id="pdiscount" class="calc" size="10"/></td>
        <td width="5%" <?php echo $style?> ><input type="text" name="disamt" id="disamt" class="calc" size="10"/></td>
       
        <!--<td align="left" <?php echo $style?>>Discount:</td>
        <td <?php echo $style?>>
          <input type="text" name="sdiscount" id="sdiscount" class="calc" size="10"/></td>-->
       
     <tr>
        <td align="left" >Total in word</td>
        <td colspan="4" align="left"><input type="text" name="totalinword" id="totalinword" tabindex="17" /></td>
        <td width="9%">&nbsp;</td>
        <td colspan="2"></td>
		<td align="left" width="10%" <?php echo $style?>>Net amount:</td>
        <td colspan="2" <?php echo $style?> >
          <input type="text" name="pnamount" id="pnamount" class="calc" size="10"/></td>
           <!--<td align="left" <?php echo $style?>>Net amount:</td>
        <td <?php echo $style?> >
          <input type="text" name="snamount" id="snamount" class="calc" size="10"/></td>-->
        </tr>
      <tr>
        <td colspan="5" align="left" ><fieldset style="display:none">
                  <legend>Transfer to Credit Note</legend>
                  <table width="100%" border="0">
                    <tr>
      	<td align="left" width="16%">Packing list no:</td>
        <td width="20%"><input type="text" name="packinglistno" id="packinglistno"  /></td>
        <td width="30%">&nbsp;</td>
        <td colspan="2" align="center"><input type="button"  class="save button" id="process" value="PROCESS"  /></td>
        </tr>
       			 </table>
        </fieldset></td>
        <td width="5%">&nbsp;</td>
         <td colspan="2"></td>
        <td width="5%" align="left" <?php echo $style?>>GST:</td>
        <td colspan="2" <?php echo $style?> ><input type="text" name="vat" id="vat" class="calc" size="10"/></td>
         <!--<td width="5%" align="left" <?php echo $style?>>GST:</td>
        <td width="8%" <?php echo $style?>><input type="text" name="servicetax" id="servicetax" class="calc" size="10"/></td>-->
      </tr>
      <tr>
        <td align="left" ></td>
        <td colspan="4" align="left"></td>
        <td></td>
        <td colspan="2"></td>
        <td align="left" width="10%" <?php echo $style?>>Grand Total:</td>
        <td colspan="2" <?php echo $style?>><input type="text" name="grtotal" id="grtotal" class="calc" size="10"/></td>
      </tr>
    </table></td>
    </tr>
  

         </table>

     
        </form>
      </div>
      <div id="message" style="width:100%; border:thin solid;text-align: center;font-weight: bold;color: #0064D1;"> </div>

</div>
<script type="text/javascript">
<?php if($orderid!='')
{?>
$(window).load(function(){
	
	//data to be from commst
	    $('#orderid').val('<?php echo clean($con,$row['orderid']); ?>');
	$('#orderdate').val('<?php if(clean($con,$row['orderdate'])!='0000-00-00') echo date_formatc(clean($con,$row['orderdate'])); ?>');
	$('#ordertype').val('<?php echo clean($con,$row['ordertype']);?>');
	$('#buyercode').val('<?php echo clean($con,$row['buyercode']); ?>');
	$('#buyerma').val('<?php echo clean($con,$client_detrow['name']); ?>');
	$('#adress').val('<?php echo clean($con,$client_detrow['address']); ?>');
	$('#city').val('<?php echo clean($con,$client_detrow['cmpcity']); ?>');
	$('#pincode').val('<?php echo clean($con,$client_detrow['pincode']); ?>');
	$('#agent').val('<?php echo clean($con,$agentcoderow['name']); ?>');
	$('#agentcode').val('<?php echo clean($con,$row['agentcode']);?>');	
	$('#distrcode').val('<?php echo clean($con,$row['distr']); ?>');
	$('#distrname').val('<?php echo clean($con,$distrcoderow['name']);?>');	
	$('#refno').val('<?php echo clean($con,$row['refno']); ?>');
	$('#dlvdate').val('<?php  if(clean($con,$row['dlvdate'])!='0000-00-00') echo date_formatc(clean($con,$row['dlvdate'])); ?>');
	$('#ratetype').val('<?php echo clean($con,$row['ratetype']);?>');
	$('#rtvalue').val('<?php echo clean($con,$row['rtvalue']);?>');
	$('#shipto').val('<?php echo clean($con,$row['shipto']);?>');
	$('#shipvia').val('<?php echo clean($con,$row['shipvia']);?>');
	$('#waybillno').val('<?php echo clean($con,$row['waybillno']);?>');
	$('#shippingpaid').val('<?php echo clean($con,$row['shippingpaid']); ?>');
	$('#comm').val('<?php echo clean($con,$row['comm']); ?>');
	$('#comm_on').val('<?php echo clean($con,$row['comm_on']); ?>');
	$('#notes').val('<?php echo clean($con,$row['notes']); ?>');
	$('#packinglistno').val('<?php echo clean($con,$row['packinglistno']); ?>');
	$('#ptotal').val('<?php echo clean($con,$row['ptotal']); ?>');
	$('#pdiscount').val('<?php echo clean($con,$row['pdiscount']); ?>');
	$('#pnamount').val('<?php echo clean($con,$row['pnamount']); ?>');
	$('#vat').val('<?php echo clean($con,$row['vat']); ?>');
	$('#grtotal').val('<?php echo clean($con,$row['grtotal']); ?>');
	$('#status').val('<?php echo clean($con,$row['status']); ?>');
	$('#disamt').val('<?php echo clean($con,$row['disamt']); ?>');
	
	
	$('#invdate').val('<?php  if(clean($con,$row['invdate'])!='0000-00-00') echo date_formatc(clean($con,$row['invdate'])); ?>');
	$('#invno').val('<?php echo clean($con,$row['invno']); ?>');
	$('#lrno').val('<?php echo clean($con,$row['lrno']); ?>');
	$('#lrdate').val('<?php  if(clean($con,$row['lrdate'])!='0000-00-00') echo date_formatc(clean($con,$row['lrdate'])); ?>');


	$('#jobdet_container').html('<?php echo clean($con,$table); ?>');
	$(document).ready(function(){
	if($('#cat').val()=='SERVICES'){
	
	}
		
		if ($('#orderid').val()==''||$('#packinglistno').val()!=''){
			$('#process').hide();}
		else
		{
			$('#process').show();
		}
			$("#guesmas").hide();
			$('#Update').show();
			$('#Save').hide();
	run();
	inline_edit();
	jobentry_rel();
	
	
		$("#ratetype").autocomplete(
		 "../../attend_by_fill.php?mode=rateonp",
	  {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
  			cacheLength:10,
			mustMatch:1,
			onItemSelect:function(row){
				if(row.data[0]!='undefined')
				$('#rtvalue').val(row.data[0]);			
				
								
			},
			showResult:function(row,data) {
    			return row+"|"+data[0];
  			},
  			autoFill:false
  		});
	
	});
	
	
	

	
	});
<?php }
else 
 ?>
$('#orderid').focus();
	
$(window).load(function() {
	
	$('#transperent').hide();
	var div_scr = $('#jobdet_container');
	div_scr.scrollTop(div_scr.prop("scrollHeight"));
	
});


	
	$("#buyercode").autocomplete(
      "client_fill.php",
      {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
			mustMatch:0,
  			cacheLength:10,
			sortResults :false,
  			onItemSelect:function(row){
				if(row.data[0]!='undefined')
				$('#buyerma').val(row.data[0]);
				if(row.data[1]!='undefined')
				$('#adress').val(row.data[1]);	
				if(row.data[2]!='undefined')
				$('#city').val(row.data[2]);
				if(row.data[3]!='undefined')
				$('#pincode').val(row.data[3]);	
				if(row.data[4]!='undefined')
				$('#ratetype').val(row.data[4]);
				if(row.data[5]!='undefined')
				$('#rtvalue').val(row.data[5]);
				if(row.data[6]!='undefined')
				$('#pdiscount').val(row.data[6]);					
				$("#guesmas").hide();												
			},
		showResult:function(row,data) {
    	return row+"|"+data[0];
  		},
			onNoMatch:function(){

				$("#guesmas").show();
				},
  		
  			autoFill:false
  		});
	
	
	
	
	
	$("#agentcode").autocomplete(
      "../../client_fill.php",
      {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
			mustMatch:0,
  			cacheLength:10,
			sortResults :false,
  			onItemSelect:function(row){
				if(row.data[0]!='undefined')
				$('#agent').val(row.data[0]);
						
								
			},
			showResult:function(row,data) {
    	return row+"|"+data[0];
  		},
  		
  			autoFill:false
  		});
		
		
		
	$("#distrcode").autocomplete(
      "../../client_fill.php",
      {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
			mustMatch:0,
  			cacheLength:10,
			sortResults :false,
  			onItemSelect:function(row){
				if(row.data[0]!='undefined')
				$('#distrname').val(row.data[0]);
						
								
			},
			showResult:function(row,data) {
    	return row+"|"+data[0];
  		},
  		
  			autoFill:false
  		});
		
		
	
	$("#shipto").autocomplete(
      "../../client_fill.php?",
      {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
			
  			cacheLength:10,
  			autoFill:false
  		});
	

</script>

</body>
</html>