<?php 
if($_REQUEST['Save'])
{

  


    
	date_default_timezone_set('Asia/Kolkata');
	$data['sheet_date']           =FormatDateForSQL($_REQUEST['sheet_date']);
	$data['checked_by']           =$_REQUEST['checked_by'];	
	$data['prepared_by']          =$_REQUEST['prepared_by'];
	$data['authorized_by']        =$_REQUEST['authorized_by'];
	$data['modified_by']           =$_SESSION['UserID'];
	$data['modified_date']         =date("Y-m-d H:i:s");
	$data['CompanyID']            =$_SESSION['ACGCompanyId'];
	$data['remarks']              =$_REQUEST['remarks1'];
	$cond="id='".$_REQUEST['SOrderId']."'";
	$row= $s->RecordEdit('faberication_main', $data,$cond);
	
	
	$data_arr1=array();
	$delete=DB_query("delete from faberication_main_child_item where parent_id='".$_REQUEST['SOrderId']."'",$db);
	for($k1=0;$k1<count($_REQUEST['itemid']);$k1++)
	{
			
		$data_arr1['parent_id']=$_REQUEST['SOrderId'];
		$data_arr1['itemid']=$_REQUEST['itemid'][$k1];
		$data_arr1['size']=$_REQUEST['sizeid'][$k1];
		$data_arr1['qty']=$_REQUEST['qty'][$k1];
		$rowinsert= $s->RecordInsert('faberication_main_child_item', $data_arr1);
		
	}
	
	
	
	
	$data_arr=array();
	$delete=DB_query("delete from faberication_main_child where parentid='".$_REQUEST['SOrderId']."'",$db);
	for($k=0;$k<count($_REQUEST['parameter']);$k++)
	{
	if($_REQUEST['specification'][$k]!='')
	{	
	$data_arr['parentid']=$_REQUEST['SOrderId'];
	$data_arr['groupid']=$_REQUEST['group'][$k];
	$data_arr['parameter']=$_REQUEST['parameter'][$k];
	$data_arr['specificatin']=$_REQUEST['specification'][$k];
	$data_arr['remarks']=$_REQUEST['remarks'][$k];
	$rowinsert= $s->RecordInsert('faberication_main_child', $data_arr);

	
	
	}
	}
	
	
	
	$s->pageLocation('index.php?route=CRM/fabrication_index&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
	
		
	
}

$sql_fetch=DB_query("select * from faberication_main where id='".$_REQUEST['SOrderId']."'",$db);
$sql_fetch_data=DB_fetch_array($sql_fetch);
extract($sql_fetch_data);
?>
<center> <h2>Fabrication Sheet</h2>
</center>
<form action="" method="post">
<fieldset><legend style="font-size:13px;"><strong>General Details</strong></legend>
<table width="100%" align="center" border="1" cellpadding="2" cellspacing="1">
  <tr>
    <th width="13%"><strong>Branch</strong></th>
    <td width="20%"> <?php 
	  $sql_branch=DB_fetch_array(DB_query("select * from locations where loccode='".$site."' and  CompanyId='".$_SESSION['ACGCompanyId']."'",$db)); ?>
	<input type="text" readonly="true" style="width:100%;"  value="<?php echo $sql_branch['locationname'];  ?>"   /> </td>
    <th width="13%"><strong>Sheet No.</strong></th>
    <td width="20%"><input name="sheet_no" id="sheet_no" type="text" class="" style="width:100%;" 
	value="<?php  echo $sheet_no;  ?>" readonly="readonly" />    </td>
    <th><strong>Sheet Date</strong></th>
    <td width="20%"><input name="sheet_date" id="sheet_date" type="text" class="datepicker" style="width:100%;"
	value="<?php echo ConvertSQLDate($sheet_date) ; ?>" /></td>
  </tr>
  <tr>
    <th><strong>Client</strong></th>
    <td><input type="text" style="width:100%;" name="party1" id="party1" readonly 
	value="<?php echo $s->getField('clientmaster','id',$client,'c_name'); ?>"   />
	<input type="hidden" name="client" value="<?php echo $client; ?>" />
	
	</td>
    <th><strong>Against MMS</strong></th>
    <td><input type="text" style="width:100%;" name="against_indent1" id="against_indent" 
	value="<?php echo $s->getField('measurment_sheet_main','id',$against_indent,'mms_no') ?>" readonly="readonly">
	<input type="hidden" style="width:100%;" name="against_indent" id="against_indent" value="<?php echo $against_indent; ?>">
       </td>
    <th><strong>MMS Date</strong></th>
    <td><input name="date" id="date" type="text"  style="width:100%;"
	 value="<?php echo ConvertSQLDate($s->getField('measurment_sheet_main','id',$against_indent,'mms_date') )?>"  readonly="readonly"/></td>
  </tr>
  
  <tr>
    <th><strong>Consignee</strong></th>
    <td>       	<?php
	$consignee_sql=DB_fetch_array(DB_query("SELECT * FROM clientmaster_consignee_address where id='".$consignee."'",$db)); ?>
	<input type="text"  name="client_name" style="width:100%;"  value="<?php echo $consignee_sql['consignee_name']; ?>"  readonly="true"/>
	</td>
    <th><strong>Type of Sheet</strong></th>
    <td><input type="text" style="width:100%;" name="type_sheet" id="type_sheet" 
	value="<?php echo $type_of_sheet;?> " readonly="readonly">
    </td>
    <th><strong>Type</strong></th>
	<?php $ty_nm=DB_fetch_array(DB_query("SELECT name FROM type_master WHERE id='".$type."'",$db)); ?>
    <td><input type="text" style="width:100%;" name="type"  id="type"  value="<?php echo $ty_nm['name'];?> "  readonly="readonly">
	
</td>
  </tr>
</table>
</fieldset>
<br />

<fieldset><legend style="font-size:13px;"><strong>Item Details

</strong></legend>
<table width="100%" border="1" cellpadding="2" cellspacing="1">
  <tr>
    <th width="5%">Sr No</th>
    <th width="20%">Item Name</th>
    <th width="33%" align="left">Size</th>
    <th align="left">Qty</th>
	<th align="left">Unit</th>
	
  </tr>
<?php
$k1=1;
$sql=DB_query("select * from faberication_main_child_item  where  parent_id='".$_REQUEST['SOrderId']."'",$db);
while($row2=DB_fetch_array($sql))
{

$unitid=$s->getField('item_master','id',$row2['itemid'],'mst_unitid');
$unit=$s->getField('unitsofmeasure','unitid',$unitid,'unitname');

?>
 <tr>
 <td><?php  echo $k1;    ?></td>
 <td><?php  echo $s->getField('item_master','id',$row2['itemid'],'item_name');   ?>
 <input type="hidden" name="itemid[]" value="<?php echo $row2['itemid'] ?>" />
 </td>
 <td><?php  echo $s->getField('size_master','id',$row2['size'],'size');   ?>
 <input type="hidden" name="sizeid[]" value="<?php echo $row2['size']?>" />
 </td>
 <td><input type="text" name="qty[]" value="<?php  echo $row2['qty'];   ?>" readonly="readonly" /> </td>
 <td><?php  echo $unit;   ?></td> 
  
  </tr>
 <?php $k1++; } ?> 
  
  </table>
  </fieldset>





<?php
$sql=DB_query("select * from fabrication_group where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
while($row=DB_fetch_array($sql))
{
if($s->getField('fabrication_group_parameter','frm_id',$row['id'],'frm_id')==$row['id']) 
{ 

?>

<fieldset><legend style="font-size:13px;"><strong><?php echo $row['group_name']; ?>

</strong></legend>
<table width="100%" border="1" cellpadding="2" cellspacing="1">
  <tr>
    <th width="5%">Sr No</th>
    <th width="20%">Parameter</th>
    <th width="33%" align="left">Specification</th>
    <th align="left">Remarks</th>
  </tr>
  
  <?php 
  $data1=array();
  $sql25=DB_query("select * from faberication_main_child where parentid='".$id."'",$db);
  while($row22=DB_fetch_array($sql25))
  {
  $data1[]=$row22['specificatin'];
  }
  
  
  $i=1;
  $sql1=DB_query("select * from fabrication_group_parameter where frm_id='".$row['id']."' and parant_id=0",$db);
  while($row2=DB_fetch_array($sql1))
  {
  
  
  ?>
  <tr>
    <td><?php echo $i; ?></td>
    <td><?php  echo $row2['terms_conditions']; ?>
	<input type="hidden" name="parameter[]" value="<?php echo  $row2['id']; ?>" />
	<input type="hidden" name="group[]" value="<?php echo $row['id']; ?> " />
	</td>
    <td><select style="width:100%;" name="specification[]" id="specification">
      <option value="">--Select--</option>
     <?php
	 $sql3=DB_query("select * from  fabrication_group_parameter where parant_id='".$row2['id']."' ",$db);
	 while($row1=DB_fetch_array($sql3))
	 {
	 $c='';
	if(in_array($row1['id'],$data1))
	 {
	  $c="selected";
	 }
	 
	  ?>
	 <option value="<?php echo $row1['id']; ?>" <?php echo $c; ?>><?php echo $row1['terms_conditions']; ?></option>
	 <?php } ?>
    </select></td>
	<?php 

	   $remarks1=$s->getField('faberication_main_child','parameter',$row2['id'],'remarks');
	
	?>
    <td><input name="remarks[]" id="" type="text" class="" style="width:100%;" value="<?php echo  $remarks1; ?>" /></td>
  </tr>
  <?php $i++; }?>
  
  
</table>


</fieldset>
<?php  } } ?>
<br />

<br />
<table width="100%" align="center" border="1" cellpadding="2" cellspacing="1">
 <tr>
    <th>Remarks</th>
    <td colspan="5">
	<textarea rows="3" name="remarks1" style="width:100%"><?php echo $remarks; ?></textarea>
	</td>
  </tr>
 
  <tr>
    <th width="13%"><strong>Prepared By </strong></th>
    <td width="20%"><input type="text" name="prepared_by1" style="width:100%;"  
	value="<?php echo 	 $s->getField('www_users','id',$prepared_by,'realname'); ?>"  readonly="readonly"/>
	<input type="hidden" name="prepared_by" value="<?php echo $prepared_by; ?>" />
         </td>
    <th width="13%"><strong>Checked By </strong></th>
    <td width="20%"><input name="checked_by" id="checked_by" type="text"  style="width:100%;" value="<?php echo  $checked_by   ?>" />    </td>
    <th><strong>Authorized By</strong></th>
    <td width="20%"><input type="text" name="authorized_by"   style="width:100%;"
	 value="<?php echo  $authorized_by   ?>" /></td>
  </tr>
  
</table>

<p align="center"><input type="submit" name="Save" value="Save" onclick="return validate()" class="search" />&nbsp;<input type="submit" name="Cancel" value="Cancel" class="search" /></p>
</form>