<?php 
if(isset($_REQUEST['Save']))
{
date_default_timezone_set('Asia/Kolkata');

DB_query("update  indent_so_main set  handled_by='".$_REQUEST['handled_by']."' ,  modified_date='".date("Y-m-d H:i:s")."' , modified_by='".$_SESSION['ACGCompanyId']."' where id='".$_REQUEST['SOrderId']."' ",$db);

DB_query("delete from quotation_terms_cond where parant_id='".$_REQUEST['SOrderId']."' and  frm_id='".$_REQUEST['frmid']."' and type='Indent' and company_id='".$_SESSION['ACGCompanyId']."' ",$db);
	$term=$_REQUEST['terms'];
	$condition=$_REQUEST[Terms_Condition];
	for($i=0;$i<count($_REQUEST[terms]);$i++)
	{
		if($condition[$i]=="")
		$condition_value="";
		else
		$condition_value=$condition[$i];
		
		DB_query("insert into `quotation_terms_cond`(parant_id,termsid,condid,frm_id,company_id,type) values('".$_REQUEST['SOrderId']."','".$term[$i]."','".$condition_value."','".$_REQUEST['frmid']."','".$_SESSION['ACGCompanyId']."','Indent')",$db);
	}

   $s->pageLocation("index.php?route=CRM/fabrication_index".$rurl);
}
?>

<?php 
$indent_row=DB_fetch_assoc(DB_query("select * from indent_so_main where CompanyID='".$_SESSION['ACGCompanyId']."' and id='".$_REQUEST['SOrderId']."'",$db));

?>
<link rel="stylesheet" href="css/new_mxerp.css"><div class="body_contain">
<div class="tab_div">
<h1>Indent Edit </h1>
<form method="post">
<table width="100%" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td class="tabledata1"><strong>Branch</strong></td>
	<?php $location=DB_fetch_array(DB_query("SELECT locationname FROM locations WHERE loccode='".$indent_row[site]."' AND CompanyID='".$_SESSION['ACGCompanyId']."'",$db)); ?>
	<td><input type="text" style="width:150px;" name="branch" readonly id="branch" value="<?php echo $location['locationname']; ?>"  />
		</td>
	<td class="tabledata1"><strong>Indent No.</strong></td>
	<td><input name="indent_no" id="indent_no" type="text" value="<?php echo $indent_row['indent_no'];  ?>" readonly="" style="width:150px;" /></td>
	<td class="tabledata1"><strong>Indent Date<font size="3" color="#FF0000">*</font></strong></td>
	<td><input readonly name="indent_date" id="indent_date" type="text"  style="width:150px;" value="<?php echo date('d/m/y',strtotime($indent_row[indent_date])); ?>" /></td>
</tr>
<tr class="row1">
	<td class="tabledata1"><strong>Format</strong></td>
	<td><input type="text" name="format" id="format" value="<?php echo $indent_row['format']; ?>" readonly style="width:150px;" /></td>
	<td class="tabledata1"><strong>Type of Order</strong></td>
	<td><input type="text" style="width:150px;" name="order_type" id="order_type" readonly value="<?php if($indent_row['order_type']=='Material')
		  echo 'Material';
		  else if($indent_row['order_type']=='Supply')
		  echo 'Supply';
		  else
		  echo 'Composite'; ?>" /></td>
	<td class="tabledata1"><strong>Type<font size="3" color="#FF0000">*</font></strong></td>
	<td>
	<?php $ty_nm=DB_fetch_array(DB_query(" select * from  type_master where id='".$indent_row['type']."' ",$db));?>
			<input type="text" name="type" id="type" value="<?php echo $ty_nm['name']; ?>" readonly style="width:150px;" />
	</td>
</tr>
<tr class="row1">
	<td class="tabledata1"><strong>Client</strong></td>
	<?php $client_name=DB_fetch_assoc(DB_query("SELECT c_name FROM `clientmaster` WHERE CompanyId='".$_SESSION['ACGCompanyId']."' and id='".$indent_row['client']."'",$db));?>
	<td><input type="text" style="width:150px;" name="party1" id="party1" readonly value="<?php echo $client_name['c_name']; ?>"  /></td>
	<td class="tabledata1"><strong>Work Order No</strong></td>
	<td><input type="text" style="width:150px;" name="order_no" id="order_no" readonly value="<?php echo $indent_row['work_order_no']?>"  /></td>
	
	<?php // $id1=$s->getField('salesorder','orderNo',$indent_row['work_order_no'],'id'); ?>
	<td class="tabledata1"><strong>Order Date</strong></td>
	<td><input name="order_date" id="order_date" type="text" readonly value="<?php echo ConvertSQLDate($indent_row['order_date']); ?>" style="width:150px;" /></td>
</tr>
<tr class="row1">
	<td class="tabledata1"><strong>P.O. No</strong></td>
	<td><input name="po_no" id="po_no" type="text" style="width:150px;" readonly value="<?php echo $indent_row['po_no']; ?>" /></td>
	<td class="tabledata1"><strong>Po. Date</strong></td>
	<td><input name="po_date" id="po_date" type="text" readonly value="<?php  echo ConvertSQLDate($indent_row['po_date']);?>" style="width:150px;" /></td>
	<td class="tabledata1"><strong>Delivery Date</strong></td>
	<td><input name="delivery_date" id="delivery_date" type="text" readonly value="<?php echo ConvertSQLDate($indent_row['delivery_date']); ?>" style="width:150px;" /></td>
</tr>
<tr class="row1">
	<td class="tabledata1"><strong>Consignee<font size="3" color="#FF0000">*</font></strong></td>
	
		<?php $sqlConsi=DB_fetch_array(DB_query("SELECT * FROM clientmaster_consignee_address where id='".$indent_row['consignee']."'",$db));  ?>
	<td><input type="text"  value="<?php echo  $sqlConsi['consignee_name']; ?>" readonly  style="width:150px;"  />	</td>
	
	<td class="tabledata1"><strong>Cont. Person</strong></td>
	<td>	<?php $sqlcontact=DB_fetch_array(DB_query("SELECT * FROM contact_information_master where id='".$indent_row['cont_person']."'",$db)); ?>
		<input  type="text" value="<?php  echo  $sqlcontact['person']; ?>" readonly style="width:150px;" />
		</td>
	<td class="tabledata1"><strong>Mobile No.</strong></td>
	<td><input name="contactMobileno" id="contactMobileno" type="text" value="<?php echo  $sqlcontact['phone']; ?>" readonly style="width:150px;" /></td>
</tr>
<tr class="row1">

<?php $cli_det=DB_fetch_array(DB_query("select credit_limit,credit_days from clientmaster where id='" .$client."' ",$db))?>
	<td class="tabledata1"><strong>Credit Limit </strong></td>
	<td><input name="credit_limit" id="credit_limit" type="text" readonly value="<?php echo $indent_row['credit_limit'] ;?>" class="" style="width:150px;" /></td>
	<td class="tabledata1"><strong>Current Bal.</strong></td>
	<td><input name="current_bal" id="current_bal" type="text" class="" readonly value="<?php echo $indent_row['current_bal'] ;?>" style="width:150px;" /></td>
	<td class="tabledata1"><strong>Credit Days</strong></td>
	<td><input name="credit_days" id="credit_days" type="text" class="" readonly value="<?php echo $indent_row['credit_days'] ;?>" style="width:150px;" /></td>
</tr>
<tr class="row1">
	<td class="tabledata1"><strong>Handled By<font size="3" color="#FF0000">*</font></strong></td>
	<td><select style="width:150px;" name="handled_by" id="handled_by">
			<option value="0">Select</option>
			<?php $sqlEmplo=DB_query("SELECT * FROM empmaster WHERE CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
			while($Handles=DB_fetch_array($sqlEmplo)){?>
				<option value="<?php echo $Handles['id']; ?>" <?php if($indent_row['handled_by']==$Handles['id']){  ?> selected="selected" <?php } ?>  ><?php echo $Handles['emp_name']; ?></option>
			<?php }?>
	</select></td>
	<td class="tabledata1"><strong>Fabrication No</strong></td>
	<?php $sheet=DB_fetch_assoc(DB_query("SELECT sheet_no FROM `faberication_main` WHERE id='".$indent_row['faberication']."'",$db));?>
	<td><input type="text" name="" value="<?php echo $sheet[sheet_no];?>" readonly="readonly" style="width:150px;"/>
	</td>
	 <td class="tabledata1"><strong>MMS No</strong></td>
	<td ><input type="text" name="" value="<?php echo $s->getField('measurment_sheet_main','id',$indent_row['mms'],'mms_no'); ?>" readonly="readonly" style="width:150px;"/>
	<input type="hidden" name="mmsno"  value="<?php echo $against_indent; ?>" />
	<input type="hidden" name="sopno" value="<?php echo $_REQUEST['SID']; ?> " /></td>
</tr>

<tr class="row1">
	<td class="tabledata1" colspan="6">
		<table width="100%" border="1" cellpadding="2" cellspacing="1">
		<tr class="row1">
			<td class="tabledata">Sr. No.</td>
			<td class="tabledata">Part Code</td>
			<td class="tabledata">Part Name</td>
			<td class="tabledata">Size</td>
			<td class="tabledata">Unit</td>
			<td class="tabledata">Qty.</td>
			<td class="tabledata">Rate</td>
			<td class="tabledata">Amount</td>
		</tr>
		<?php		
		$indent_detail_query=DB_query("SELECT * FROM `indent_so_main_details` WHERE parent_id='".$_REQUEST[SOrderId]."'",$db);
		while($indent_detail1=DB_fetch_assoc($indent_detail_query))
		{
			$indent_detail[]=$indent_detail1;
		}
$j=1;
		foreach($indent_detail as $i){
		?>
		<tr class="row1">
			<td><?php echo $j; ?></td>
			<?php $item_name=DB_fetch_assoc(DB_query("SELECT mst_unitid,item_name,StockID FROM item_master WHERE id='".$i[mst_itemid]."'",$db));?>
			<td><?php echo $item_name['item_name']; ?></td>
			<td><?php echo $item_name['StockID']; ?></td>
			<td>
			<?php $SQLSize=DB_fetch_assoc(DB_query("SELECT size FROM size_master where id='".$i[size]."' and  CompanyId='".$_SESSION['ACGCompanyId']."'",$db)); echo $SQLSize[size]; ?>
		</td>
			<td><?php $unit_name=DB_fetch_assoc(DB_query("SELECT * FROM `unitsofmeasure` WHERE unitid='".$item_name['mst_unitid']."'",$db)); echo $unit_name['unitname']; ?></td>
			<td><input type="text" name="pri_qty[]" id="pri_qty" readonly value="<?php echo $i['qty']; ?>" 
			style="width:80px;" /></td>
			
			<td><input type="text" name="rate" readonly id="rate" value="<?php echo $i['rate']; ?>"  
			style="width:80px;" /></td>
			<td>		
			<input type="text" name="amount" readonly id="amount" 
			value="<?php echo $i['amount']; ?>"  style="width:80px;" /></td>
		</tr>
		<?php $j+=1;} ?>
</table>
	</td>
</tr>
</table>
<p align="left"><b>Assembly Item details</b></p>
<table align='center' width='100%;' border='1' cellpadding='3' cellspacing='0'>
</tr>
<tr class='row1'>
<td class='tabledata'>Sr. No.</td>
<td class='tabledata'>&nbsp;</td>
<td class='tabledata'>Item Code</td>
<td class='tabledata'>Item Name</td>
<td class='tabledata'>Qty.</td>
<td class='tabledata'>Price</td>
<td class='tabledata'>Per Unit</td>
<td class='tabledata'>Value</td>
<td class='tabledata'>Discount Type</td>
<td class='tabledata'>Discount Per</td>
<td class='tabledata'>Discount Price</td>
<td class='tabledata'>Value After Discount</td>

</tr>
<?php 
$sql_hrd=DB_query("SELECT * FROM `indent_so_main_hrditem_details` WHERE parent_id='".$_REQUEST[SOrderId]."'",$db);
while($hrdwr_details1=DB_fetch_assoc($sql_hrd))
{
	$hrdwr_details[]=$hrdwr_details1;
}
$k=1;
foreach($hrdwr_details as $j)
{
?>
<tr class='row1'>
<td style='white-space:nowrap;' class='tabledata'><?php echo $k; ?></td>	
<td class='tabledata'><input type='hidden' name='item_code[]' id="itemid1_<?php echo $k; ?>" style='width:60px;' 
value="<?php echo $row['itemCode'] ?>" /></td>
<?php $item_name=DB_fetch_assoc(DB_query("SELECT mst_unitid,item_name,StockID FROM item_master WHERE id='".$j[mst_itemid]."'",$db));?>
<td class='tabledata'><input type='text' style='width:60px;' readonly value="<?php echo $item_name['StockID']; ?>"  /></td>

<td class='tabledata' style='white-space:nowrap'><input readonly type='text' style='width:150px;'  id=''  value="<?php echo $item_name['item_name']; ?>"  /></td>
<td class='tabledata'><input type='text' readonly style='width:50px;' value="<?php echo $j['qty']; ?>" /></td>
<td class='tabledata'>
<input type='text' name='stock_price' readonly value="<?php echo $j['price']; ?>"   style='width:50px;'/></td>
<td class='tabledata'><input type='text' readonly name='stock_perunit' onfocus='filldefaultAmt(this.value,this.id)' style='width:30px;' value="<?php echo $j['perunit']; ?>"/></td>
<td class='tabledata'><input type='text' name='stock_value' readonly value="<?php echo $j['amount']; ?>"  style='width:60px;' onfocus='CalculateTotalLeadAmt(this.value,this.id)'/></td>
<td class='tabledata'>
	<input type="text" name="PerAmo" readonly value="<?php if($j['discounttype']=="Amount") echo "Amount"; else if($j['discounttype']=="PercentAmt") echo "Percent Amt"  ; ?>" />
		</td>
<td class='tabledata'><input type='text' style='width:50px' name='Discount' readonly  value="<?php echo $j['Discount']; ?>"/></td>
<td class='tabledata'><input type='text' style='width:50px' name='perc' readonly='true' value="<?php echo $j['perc_amt']; ?>" /></td>
<td class='tabledata'><input type='text' style='width:70px' name='value_dis' readonly='true'
value="<?php echo $j['afterdis']; ?>" /></td>
</tr>
<?php $k+=1;}?>
</table>

</table>

<table width="100%" cellpadding="3" cellspacing="0" border="1">
<tr class="row1">
	<td width="50%" valign="top">
		<table width="100%" border="0" cellspacing="0" cellpadding="3" align="left">
			<tr class="row1">
				<td class="tabledata1" style="text-align:center;" colspan="2">Terms And Conditions</td>
			</tr>
			<?php $i=0;
			$data_quotes=array();
			$sql_quotes=DB_query("select * from  quotation_terms_cond where parant_id='".$_REQUEST['SOrderId']."' and  frm_id='".$_REQUEST['frmid']."' and  type='Indent' and company_id='".$_SESSION['ACGCompanyId']."'  ",$db);
			while($sql_row_quotes=DB_fetch_array($sql_quotes))
			{
			if($sql_row_quotes['condid']!=0)
			$data_quotes[]=$sql_row_quotes['condid'];
			}			
			//$data11=implode("','",$data_quotes);

			
			
			
			$SQLTerms=DB_query("SELECT * FROM terms_condition where parant_id=0 and CompanyId='".$_SESSION['ACGCompanyId']."' and frm_id='".$_REQUEST['frmid']."'",$db); 
			while($TermsAndCond=DB_fetch_array($SQLTerms)){?>
			<tr class="row1">
				<td class="tabledata1"><?php echo $TermsAndCond['terms_conditions']; ?>
				<input type="hidden" name="terms[]" id="terms" value="<?php echo $TermsAndCond['id']; ?>" />
				</td>
				<td><select name="Terms_Condition[]" id="Terms_Condition">
						<option value="">Select</option>
						<?php $SQLCond=DB_query("SELECT * FROM terms_condition where parant_id='".$TermsAndCond['id']."'",$db);
						while($GetCond=DB_fetch_array($SQLCond)){
						if(in_array($GetCond['id'],$data_quotes))
						{
						
						$d="selected";
						}
						else
						{
						
						$d='';	
						}
						?>
	<option value="<?php echo $GetCond['id']; ?>"  <?php echo $d; ?>><?php echo $GetCond['terms_conditions']; ?></option>
						<?php }?>
				</select></td>
			</tr>
<?php $i++;}?>
		</table>
	</td>
	<td width="50%">
		<table width="100%" border="0" cellspacing="0" cellpadding="3" align="right">
			<tr class="row1">
				<td class="tabledata1" style="text-align:center;" colspan="4">Amount And Taxes</td>
			</tr>
			
			
			
			
			<tr class="row1">
					<td class="tabledata1">Basic Amount<label><font color="#FF0000">*</font></label></td>
					<td colspan="3"><input name="basicAmount" type="text" value="<?php echo $indent_row['basic'];?>" style="width:150px;" readonly /></td>
			  </tr>
			<tr class="row1">
			<td>Discount Type</td>
			<td><input type="text" style="width:150px" name="PerAmount" id="PerAmount"  readonly="true" value="
<?php if($indent_row['dis_type']=='Amount') echo "Amount"; else if($indent_row['dis_type']=='PercentAmt') echo "Percent Amt"; ?>"  />
	</td>
			<td><input type="text" style="width:35px" name="Discount_amount" readonly id="Discount_amount" 
onkeyup="DiscountAmountvalue(this.value)" value="<?php echo $indent_row['dis_per']; ?>" /></td>
			<td>&nbsp;</td>
			</tr>
		  <tr class="row1">
<td>Discount Amt</td><td><input type="text" style="width:150px" name="discountperc" id="discountperc"  readonly="true" value="
<?php echo $indent_row['dis_amt']; ?>"  /></td>
			<td>Discounted Amt</td>
			<td><input type="text" style="width:150px" name="afterdiscountprice" value="<?php echo $indent_row['discounted_amt']; ?>" id="afterdiscountprice"  readonly="true"  /></td>
		  </tr>	
			
			<tr class="row1">
					<td class="tabledata1">Excise Duty</td>
					<?php $exise=DB_fetch_assoc(DB_query("SELECT * FROM `excise_tax` WHERE id='".$indent_row['excise_id']."'",$db)); ?> 
					<td>
					<input type="text" style="width:150px" name="EDBillRate" id="EDBillRate" value="<?php echo $exise['caption']; ?>"  readonly="true"  />
					</td>
				    <td>Excise Amt </td>
				    <td><input name="totalDiscountedPrice" id="totalDiscountedPrice" 
				type="text"  style="width:150px;" readonly="true" value="<?php echo $indent_row['excise_amt'];?>"/>	</td>
			</tr>
			
			<tr class="row1">
					<td class="tabledata1">E-Cess</td>
					<?php
					$cess_rate=DB_fetch_array(DB_query("Select def_rate from excise_tax where id='".$indent_row['ECessID']."'",$db));
					 ?>
					
					<td><input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $cess_rate['def_rate'];?>" style="width:150px;" readonly />						</td>
					<td><span class="tabledata1">E-Cess</span> Amt </td>
					<td><input name="ECessValue" id="ECessValue" type="text" value="<?php echo $indent_row['ecess_amt']?>" style="width:150px;"readonly onfocus="calculateECess()"/></td>
			</tr>
			<tr class="row1">
					<td class="tabledata1" >SAH-E Cess </td>
			<?php
			$she_cess_rate=DB_fetch_array(DB_query("Select def_rate from excise_tax where id='".$indent_row['SHECessId']."'",$db));
			 ?>					
					<td><input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $she_cess_rate['def_rate'];?>" style="width:150px;" readonly/>						</td>
					<td><span class="tabledata1">SAH-E Cess</span> Amt </td>
					<td><input name="SAHCessValue" id="SAHCessValue" type="text" value="<?php echo $indent_row['sah_amt']?>" style="width:150px;" readonly onfocus="calculateSAHCess()"/></td>
			</tr>
			<tr class="row1">
			<td class="tabledata1">Taxable Amount<label><font color="#FF0000">*</font></label></td>
			<td><input name="taxableAmount" id="taxableAmount" type="text" value="<?php echo $indent_row['taxable_amt']?>" style="width:150px;" readonly onfocus="calculateTaxable()"/>			</td>
		    <td class="tabledata1">Hardware Amount</td>
			<td><input readonly name="hardwareamount" id="hardwareamount" type="text" style="width:150px;" value="<?php echo $indent_row['hardware_amt'] ?>" onfocus=""/>			</td>
		    </tr>
		    </tr>
		 
			<tr class="row1">
					<td class="tabledata1">Sales Tax (Taxable Amt) </td>
					<td>
					
				<?php 
				$vatSql=DB_fetch_array(DB_query("Select * from sales_tax_master where salestax_id ='".$indent_row['vat_cst']."'",$db));?>
				
				<div id="VATId"><input name="VatCstValue" id="VatCstValue" type="text" value="<?php echo $vatSql['tax_code'];?>" style="width:150px;" readonly  onfocus="calculateEditVATCST()" /></div>
				<input type="text" readonly name="" id="rate" value="<?php echo $indent_row['vat_cst_amt'];?>" /></td>
				   <td class="tabledata1">Hardware taxable Amount</td>
					<td><input readonly name="hardware_tax_amount" id="hardware_tax_amount" type="text" style="width:150px;" value="<?php echo $indent_row['sales_tax_hrdamt']?>"/>			</td>
		      </tr>
				
				<tr class="row1">
					<td class="tabledata1">Total Amt I </td>
					<td ><input type="text" name="total_taxable_amt" readonly value="<?php echo $indent_row['sales_tax_taxabelamt'];?>" id="total_taxable_amt" style="width:150px;"   /></td>
					<td colspan="2" class="tabledata1">&nbsp;</td>
				</tr>
				
				<tr class="row1">
					<td class="tabledata1">Freight Amt </td>
					<td colspan="3"><input type="text" name="freight" readonly id="freight" value="<?php echo $indent_row['freight'];?>"  style="width:150px;" /></td>
				</tr>
			<tr class="row1">
					<td class="tabledata1">Grand Total<label><font color="#FF0000">*</font></label></td>
					<td colspan="3"><input name="grandTotal" id="grandTotal" type="text"  style="width:150px;" onfocus="calculateGrand()" readonly="readonly" value="<?php echo $indent_row['grand_total']  ;?>" /></td>
			  </tr>
			</table>
	</td>
</tr>
</table>
<p align="center"><input type="submit" name="Save" value="Save" class="search" />&nbsp;<input type="submit" name="Cancel" value="Cancel" class="search" /></p>
</form>
</div>
</div>
