<?php 
if(isset($_POST['Save']))
	{
      $sql_asset_check="select id,name,under_group,asset_type from machine_center where name='".$_REQUEST['name']."' and under_group='".$_REQUEST['under_group']."' and asset_type='".$_REQUEST['asset_type']."' ";
      $result_asset_check=DB_query($sql_asset_check,$db);
      $rs_asset_check=DB_fetch_array($result_asset_check);
      $num_row=DB_num_rows($result_asset_check);
      
       if($num_row<1)
     {
		//	$path = 'Add_file/';
			
           /*  $uploads_dir = 'Add_file/';
			echo $tmp_name = $_FILES['add_file']['tmp_name'];
             $name = $_FILES['add_file']['name'];
             echo $file_name_save=$name;
             exit;
     
             move_uploaded_file($tmp_name, "$uploads_dir/$name"); */
              $FinempCode1=rand(0,9999);
             if($_FILES['add_file']['name']!='')
	   		 {
        	$name=$_FILES['add_file']['name'];
			$tmp_name=$_FILES['add_file']['tmp_name'];
			$name_brk=explode('.',$name);
			$type=$name_brk[1];
			$new_name=$FinempCode1.'.'.$type;
			$path="uploaded_docs/".$new_name;
			$file_copy=copy($tmp_name,$path);		
		  }
		    //echo $new_name;
		    //exit;
			/*if(!empty($_FILES['add_file']['name']))
			{
				echo $name = $_FILES['add_file']['name']; 
				exit;
				$tmp = $_FILES['add_file']['tmp_name'];
				move_uploaded_file($tmp, $path.$name);				
			} */



              //  exit;
			if($_REQUEST['work_location']=='')
			{
				$_REQUEST['work_location']=$_REQUEST['location'];
			}	
			$time=$_REQUEST['setup_time']." ".$_REQUEST['start_AMPM'];
			
				$data['code']                        =$_REQUEST['code_name'];
			$data['name']                        =$_REQUEST['name'];
			$data['under_group']                 =$_REQUEST['under_group'];
			$data['sr_no']                       =$_REQUEST['sr_no'];
			$data['model_no']                    =$_REQUEST['model_no'];
			$data['chesis_no']                   =$_REQUEST['chesis_no'];
			$data['warranty_type']               =$_REQUEST['warranty_type'];
			$data['add_file']                    =$new_name;
			//$data['add_file']                    =$file_name_save;
			$data['start_period']                =FormatDateForSQL($_REQUEST['start_period']);
			$data['end_period']                  =FormatDateForSQL($_REQUEST['end_period']);
			$data['status']                      =$_REQUEST['status'];
			$data['amc_on_value']                =$_REQUEST['amc_on_value'];
			$data['amc_per']                     =$_REQUEST['amc_per'];
		    $data['unit']                        =$_REQUEST['unit'];
		    $data['vehicle_no']                  =$_REQUEST['vehicle_no'];
			$data['emi_year']                    =$_REQUEST['emi_year'];
			$data['fule_type']                   =$_REQUEST['fuel_type'];
			$data['one_day_capacity']            =$_REQUEST['one_day_capacity'];
			$data['setup_time']                  =$time;
			$data['fuel_unit']                   =$_REQUEST['fuel_unit'];
			$data['reading_unit']                =$_REQUEST['reading_unit'];
			$data['average_production_qty']      =$_REQUEST['average_production_qty'];
			$data['accounting_group']            =$_REQUEST['accounting_group'];
			$data['depriciation_ac_gl']          =$_REQUEST['depriciation_ac_gl'];
			$data['sale_status']                 =$_REQUEST['sale_status'];
			$data['sale_amount']                 =$_REQUEST['sale_amount'];
		    $data['working']                     =$_REQUEST['working'];
			$data['sale_date']                   =FormatDateForSQL($_REQUEST['sale_date']);
			$data['sale_party']                  =$_REQUEST['sale_party'];
		    $data['purchase_amt']                =$_REQUEST['purchase_amount'];
		    $data['service_time']                =$_REQUEST['service_time'];
			$data['purchase_date']               =FormatDateForSQL($_REQUEST['purchase_date']);
			$data['purchase_party']              =$_REQUEST['purchase_party'];
		    $data['manchine_opening_date']       =FormatDateForSQL($_REQUEST['opening_machine_date']);
			$data['accumulative_depriciation']   =FormatDateForSQL($_REQUEST['accumlative_depriciation']);
			$data['total_till_date']             =$_REQUEST['total_till_date'];
			$data['location']                    =$_REQUEST['location'];
			$data['work_location']               =$_REQUEST['work_location'];
			$data['insatallation_by']            =$_REQUEST['installation_by'];
			$data['date']                        =FormatDateForSQL($_REQUEST['date']);
			$data['CompanyId']                   = $_SESSION['ACGCompanyId'];
		    $data['dep_as_per_com']              =$_REQUEST['dep_as_per_com'];
			$data['dep_as_per_inc']              =$_REQUEST['dep_as_per_inc'];
		    $data['accumlative_depriciation_dep']=$_REQUEST['accumlative_depriciation_dep'];
			$data['asset_life']                  =$_REQUEST['asset_life'];
		    $data['loc']                         =$_REQUEST['loc'];
		    $data['description']                 =$_REQUEST['description'];
		    $data['title11']                     =$_REQUEST['title11'];
		    $data['title12']                     =$_REQUEST['title12'];
		    $data['title13']                     =$_REQUEST['title13'];
		    $data['title14']                     =$_REQUEST['title14'];
		    $data['title15']                     =$_REQUEST['title15'];
		    $data['title16']                     =$_REQUEST['title16'];
		    $data['title17']                     =$_REQUEST['title17'];
		    $data['title18']                     =$_REQUEST['title18'];
		    $data['title19']                     =$_REQUEST['title19'];
		    $data['title20']                     =$_REQUEST['title20'];
		    $data['title21']                     =$_REQUEST['title21'];
		    $data['asset_type']                  =$_REQUEST['asset_type'];

		    $data['source']                       =$_REQUEST['source'];
		    $data['quantity']                     =$_REQUEST['quantity'];
		    $data['net_wdv']                       =$_REQUEST['net_wdv'];
		    $data['net_wdv_date']                  =FormatDateForSQL($_REQUEST['net_wdv_date']);
		    $data['accum_date']                    =FormatDateForSQL($_REQUEST['accum_date']);
		      //  $data['capital_date']                  =FormatDateForSQL($_REQUEST['capital_date']);
		        $data['comment']                       =$_REQUEST['comment'];

			    $s->RecordInsert('machine_center', $data);
			    if($_REQUEST['asset_type']=='SA')
			    {
		         	$ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
		         	$Lastreq_id=DB_Last_Insert_ID($db,'machine_center',$ErrMsg);	
		         	$data1['machine_center_id']=$Lastreq_id;
		         	$data1['asset_id']=$_REQUEST['asset'];
		         	$s->RecordInsert('machine_center_details',$data1);
			    }
	$s->pageLocation("index.php?route=ToolPlants/fixed_assets/FixedAssetsDefinition_index".$rurl);
   }	
  else
		{
			prnMsg( _('Asset name already exists under this group'),'failure');
		         exit;
		}
     $s->pageLocation("index.php?route=ToolPlants/fixed_assets/FixedAssetsDefinition_index".$rurl);
}


if($_REQUEST['update'])
{ 
   $sql_asset_check="select id,name,under_group,asset_type from machine_center where name='".$_REQUEST['name']."' and under_group='".$_REQUEST['under_group']."' and asset_type='".$_REQUEST['asset_type']."' and id!='".$_REQUEST['fid']."' ";
   $result_asset_check=DB_query($sql_asset_check,$db);
   $rs_asset_check=DB_fetch_array($result_asset_check);
   $num_row=DB_num_rows($result_asset_check);

    if($num_row<1)
    {

			$path="ToolPlants/fixed_assets/MachineDoc/";
			if($_FILES['add_file']['name']=='')
			{
				$FileName=$_REQUEST['add_file1'];
			}
			else
			{
				//$OldFileName=$s->GetFieldValue('machine_center',"id='".$_REQUEST['fid']."'",'add_file');
				$OldFileName=$_REQUEST['add_file1'];
				if($OldFileName !=""){
					unlink($path.$OldFileName);
				}

				    $FinempCode1=rand(0,9999);
             if($_FILES['add_file']['name']!='')
	   		 {
		        	$name=$_FILES['add_file']['name'];
					$tmp_name=$_FILES['add_file']['tmp_name'];
					$name_brk=explode('.',$name);
					$type=$name_brk[1];
					$new_name=$FinempCode1.'.'.$type;
					$path="uploaded_docs/".$new_name;
					$file_copy=copy($tmp_name,$path);		
	   	  }
			}

			if($_REQUEST['work_location']=='')
			{
				$_REQUEST['work_location']=$_REQUEST['location'];
			}
			
			$time=$_REQUEST['setup_time']." ".$_REQUEST['start_AMPM'];
			
			$data['code']                        =$_REQUEST['code_name'];
			$data['name']                        =$_REQUEST['name'];
			$data['under_group']                 =$_REQUEST['under_group'];
			$data['sr_no']                       =$_REQUEST['sr_no'];
			$data['model_no']                    =$_REQUEST['model_no'];
			$data['chesis_no']                   =$_REQUEST['chesis_no'];
			$data['warranty_type']               =$_REQUEST['warranty_type'];
			$data['add_file']                    =$new_name;
			$data['start_period']                =FormatDateForSQL($_REQUEST['start_period']);
			$data['end_period']                  =FormatDateForSQL($_REQUEST['end_period']);
			$data['status']                      =$_REQUEST['status'];
			$data['amc_on_value']                =$_REQUEST['amc_on_value'];
			$data['amc_per']                     =$_REQUEST['amc_per'];
		    $data['unit']                        =$_REQUEST['unit'];
		    $data['vehicle_no']                  =$_REQUEST['vehicle_no'];
			$data['emi_year']                    =$_REQUEST['emi_year'];
			$data['fule_type']                   =$_REQUEST['fuel_type'];
			$data['one_day_capacity']            =$_REQUEST['one_day_capacity'];
			$data['setup_time']                  =$time;
			$data['fuel_unit']                   =$_REQUEST['fuel_unit'];
			$data['reading_unit']                =$_REQUEST['reading_unit'];
			$data['average_production_qty']      =$_REQUEST['average_production_qty'];
			$data['accounting_group']            =$_REQUEST['accounting_group'];
			$data['depriciation_ac_gl']          =$_REQUEST['depriciation_ac_gl'];
			$data['sale_status']                 =$_REQUEST['sale_status'];
			$data['sale_amount']                 =$_REQUEST['sale_amount'];
		    $data['working']                     =$_REQUEST['working'];
			$data['sale_date']                   =FormatDateForSQL($_REQUEST['sale_date']);
			$data['sale_party']                  =$_REQUEST['sale_party'];
		    $data['purchase_amt']                =$_REQUEST['purchase_amount'];
		    $data['service_time']                =$_REQUEST['service_time'];
			$data['purchase_date']               =FormatDateForSQL($_REQUEST['purchase_date']);
			$data['purchase_party']              =$_REQUEST['purchase_party'];
		    $data['manchine_opening_date']       =FormatDateForSQL($_REQUEST['opening_machine_date']);
			$data['accumulative_depriciation']   =FormatDateForSQL($_REQUEST['accumlative_depriciation']);
			$data['total_till_date']             =$_REQUEST['total_till_date'];
			$data['location']                    =$_REQUEST['location'];
			$data['work_location']               =$_REQUEST['work_location'];
			$data['insatallation_by']            =$_REQUEST['installation_by'];
			$data['date']                        =FormatDateForSQL($_REQUEST['date']);
			$data['CompanyId']                   = $_SESSION['ACGCompanyId'];
		    $data['dep_as_per_com']              =$_REQUEST['dep_as_per_com'];
			$data['dep_as_per_inc']              =$_REQUEST['dep_as_per_inc'];
		    $data['accumlative_depriciation_dep']=$_REQUEST['accumlative_depriciation_dep'];
			$data['asset_life']                  =$_REQUEST['asset_life'];
		    $data['loc']                         =$_REQUEST['loc'];
		    $data['description']                 =$_REQUEST['description'];
		    $data['title11']                     =$_REQUEST['title11'];
		    $data['title12']                     =$_REQUEST['title12'];
		    $data['title13']                     =$_REQUEST['title13'];
		    $data['title14']                     =$_REQUEST['title14'];
		    $data['title15']                     =$_REQUEST['title15'];
		    $data['title16']                     =$_REQUEST['title16'];
		    $data['title17']                     =$_REQUEST['title17'];
		    $data['title18']                     =$_REQUEST['title18'];
		    $data['title19']                     =$_REQUEST['title19'];
		    $data['title20']                     =$_REQUEST['title20'];
		    $data['title21']                     =$_REQUEST['title21'];
		    $data['asset_type']                  =$_REQUEST['asset_type'];

		    $data['source']                       =$_REQUEST['source'];
		    $data['quantity']                     =$_REQUEST['quantity'];
		    $data['net_wdv']                       =$_REQUEST['net_wdv'];
		    $data['net_wdv_date']                  =FormatDateForSQL($_REQUEST['net_wdv_date']);
		    $data['accum_date']                    =FormatDateForSQL($_REQUEST['accum_date']);
		   // $data['capital_date']                  =FormatDateForSQL($_REQUEST['capital_date']);
		    $data['comment']                       =$_REQUEST['comment'];
		    
			$cond="id='".$_REQUEST['fid']."'";	
			$s->RecordEdit('machine_center', $data, $cond);	
			 if($_REQUEST['asset_type']=='SA')
			    {
		         	$ErrMsg = _('An error occurred Record Note Save') . '. ' . _('The error says');
		         	$Lastreq_id=$_REQUEST['fid'];	
		         	//$data1['machine_center_id']=$Lastreq_id;
		         	$data1['asset_id']=$_REQUEST['asset'];
		         	$cond1="machine_center_id='".$Lastreq_id."'";
		         	$s->RecordEdit('machine_center_details',$data1,$cond1);
			    }	
    		$s->pageLocation("index.php?route=ToolPlants/fixed_assets/FixedAssetsDefinition_index".$rurl);
			
   }
   else
   {
   	  prnMsg( _('Asset name already exists! under this group'),'failure');
		exit;
   } 
    $s->pageLocation("index.php?route=ToolPlants/fixed_assets/FixedAssetsDefinition_index".$rurl);
}
$asset_type='';
	if($_REQUEST['action']=='edit')
	{
	$recEdit=DB_fetch_array($s->GetRecordById('machine_center','id='.$_REQUEST['fid']));
	extract($recEdit);
	}
	if($asset_type=='SA')
	$disabled="display:block";
	else
	$disabled="display:none";

   $title='';
   $title1=DB_query("select * from tbl_title_master order by serial_no ASC",$db);
   while($r=DB_fetch_array($title1))
   {
    $title[$r['serial_no']]=$r['title_name'];
   }  
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Asset Master</h1>
<form action="" method="post" enctype="multipart/form-data">
<h3>General Details</h3>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
		<td width="15%" align="right">Asset Type <font color="#FF0000">*</font></td>
	    <td width="20%">
		    <select name="asset_type" id="asset_type" onchange="Showasset_type(this.value)" >
					<option value="0">Select</option>
				   	<option value="A"<?php if($asset_type=='A') { ?> selected<?php } ?>>Asset</option>
					<option value="SA" <?php if($asset_type=='SA') { ?> selected<?php } ?>>Sub Asset</option>
					<option value="NA" <?php if($asset_type=='NA') { ?> selected<?php } ?>>Non Asset</option>
			</select>
		</td>
        <td width="15%" align="right">Code <font color="#FF0000">*</font></td>
        <td width="20%"><input type="text" name="code_name" id="code_name"  value="<?php echo $code; ?>" /></td>
		<td width="13%" align="right">Name<font color="#FF0000">*</font></td>
        <td><input type="text" name="name" id="name"  value="<?php echo $name; ?>"/></td>       
    </tr>
    <tr class="row1">
        <td align="right">Asset Group <font color="#FF0000">*</font></td>
        <td><select name="under_group"  id="under_group"  onChange="GetAssets(this.value);">
        <option value="0">Select</option>	
        <?php $sql="select * from machine_group_master";
		$query=DB_query($sql,$db);
		while($row1=DB_fetch_array($query))
		{
      $t1='';
      if($row1['id']==$under_group)
       $t1="selected";
			?>
			<option value="<?php echo $row1['id']; ?>" <?php echo $t1; ?>><?php echo $row1['machine_gp_location']; ?></option>
		<?php }	?>        	
        </select></td>
       <?php    $mainuint=$s->GetFieldValue("unitsofmeasure","unitname like 'Nos%'","unitid");
        ?>
        <td align="right">Unit</td>
        <td><select name="unit" >
        <option value="0">Select</option>
        <?php      
        $sql_unit=DB_query("select * from unitsofmeasure ",$db);
        while($row_sql=DB_fetch_array($sql_unit))
        {
         $t1='';
         if($row_sql['unitid']==$unit)
          $t1="selected";
         ?>
        <option value="<?php echo $row_sql['unitid']; ?>" <?php echo $t1; ?>><?php echo $row_sql['unitname']; ?></option>
        <?php } ?>
       </select>
        </td>
        <td align="right"><span id="asset_title" style="<?php echo $disabled; ?>">Asset Name</span></td>
        <td>
            <?php $asetid=$s->GetFieldValue("machine_center_details","machine_center_id='".$id."'","asset_id"); ?>
        	<select  name="asset" id="asset" style="<?php echo $disabled; ?>">
             <option value="0">Select</option>
             <?php
             $sql_asset=DB_query("select * from machine_center where CompanyId='".$_SESSION['ACGCompanyId']."' and asset_type IN ('A','NA')",$db);
             while($r=DB_fetch_array($sql_asset))
             { 
              $t1='';
              if($r['id']==$asetid)
              	$t1="selected";
             	?>
            <option value="<?php echo $r['id']; ?>"<?php echo $t1; ?>><?php echo $r['name']; ?></option>
             <?php } ?>
         </select>
        </td>
    </tr>
    <tr class="row1">
	    <!--<td align="right">Quantity</td> -->
	    <!-- <input type="hidden" name="quantity" id="quantity"  onkeypress="return isNumber(event)" value="<?php //echo $quantity; ?>"> -->
	    <td align="right">Source</td>
	    <td><select name="source" id="source" >
                 <option value="0">Select</option>
	             <option value="Grant Fund" <?php if($source=="Grant Fund") { ?> selected="selected" <?php }?> >Grant Fund</option>
	             <option value="Owned Fund" <?php if($source=="Owned Fund") {?> selected="selected" <?php } ?> >Owned Fund</option>
            </select></td>
	    <td colspan="4">&nbsp;</td>
</tr>
</table>
<br>
<h3>Other Details</h3>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">   
    	<td width="15%" align="right"><?php echo $title[1]; ?></td>
        <td width="20%"><input type="text" name="sr_no" id="sr_no"  value="<?php echo $sr_no; ?>"/></td>
        <td width="15%" align="right"><?php echo $title[2]; ?></td>
        <td width="20%"><input type="text" name="model_no" id="model_no"  value="<?php echo $model_no; ?>" /></td>
		<td width="13%" align="right"><?php echo $title[3]; ?></td>
        <td><input type="text" name="chesis_no" id="Chesis_no"  value="<?php echo $chesis_no; ?>"/></td>
</tr>   
<tr class="row1">	
     	 <td align="right"><?php echo $title[4]; ?></td>
         <td><input type="text" name="description" id="description"  value="<?php echo $description; ?>"/></td>
         <td align="right"><?php echo $title[5]; ?></td>
         <td><input type="text" name="vehicle_no" id="vehicle_no"  value="<?php echo $vehicle_no; ?>"/></td>
         <td align="right"><?php echo $title[6]; ?></td>
         <td><input type="text" name="service_time" id="service_time"  value="<?php echo $service_time; ?>"/></td>  
</tr>
 <tr class="row1">	
 	     <td align="right"><?php echo $title[7]; ?></td>
         <td><input type="text" name="status" id="status"  value="<?php echo $status; ?>" /></td> 
         <td align="right"><?php echo $title[8]; ?></td>
         <td><input type="text" name="amc_on_value" id="amc_on_value"  value="<?php echo $amc_on_value; ?>" /></td> 
         <td align="right"><?php echo $title[9]; ?></td>
         <td><input type="text" name="amc_per" id="amc_per"  value="<?php echo $amc_per; ?>" /></td> 
       
</tr>
<tr class="row1">
        <td align="right"><?php echo $title[10]; ?></td>
		<td><input type="text" name="setup_time" id="setup_time"  value="<?php echo $setup_time; ?>"/></td>   
		<td align="right"><?php echo $title[11]; ?></td>
		<td><input type="text" name="title11" id="title11"  value="<?php echo $title11; ?>"/></td>   
		<td align="right"><?php echo $title[12]; ?></td>
		<td><input type="text" name="title12" id="title12"  value="<?php echo $title12; ?>"/></td>   
</tr>
<tr class="row1">
        <td align="right"><?php echo $title[13]; ?></td>
		<td><input type="text" name="title13" id="title13"  value="<?php echo $title13; ?>"/></td>   
		<td align="right"><?php echo $title[14]; ?></td>
		<td><input type="text" name="title14" id="title14"  value="<?php echo $title14; ?>"/></td>   
		<td align="right"><?php echo $title[15]; ?></td>
		<td><input type="text" name="title15" id="title15"  value="<?php echo $title15; ?>"/></td>   
</tr>
<tr class="row1">
        <td align="right"><?php echo $title[16]; ?></td>
		<td><input type="text" name="title16" id="title16"  value="<?php echo $title16; ?>"/></td>   
		<td align="right"><?php echo $title[17]; ?></td>
		<td><input type="text" name="title17" id="title17"  value="<?php echo $title17; ?>"/></td>   
		<td align="right"><?php echo $title[18]; ?></td>
		<td><input type="text" name="title18" id="title18"  value="<?php echo $title18; ?>"/></td>   
</tr>
<tr class="row1">
        <td align="right"><?php echo $title[19]; ?></td>
		<td><input type="text" name="title19" id="title19"  value="<?php echo $title19; ?>"/></td>   
		<td align="right"><?php echo $title[20]; ?></td>
		<td><input type="text" name="title20" id="title20"  value="<?php echo $title20; ?>"/></td>   
		<td align="right"><?php echo $title[21]; ?></td>
		<td><input type="text" name="title21" id="title21"  value="<?php echo $title21; ?>"/></td>   
</tr>
</table>
<br>
<h3>Warranty</h3>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
        <td width="15%" align="right">Warranty Type</td>
        <td width="20%"><select name="warranty_type" id="warranty_type" >
        <option value="0">--Select---</option>
        <option value="Y"<?php if($warranty_type=='Y') { ?> selected="selected" <?php } ?>>Yes</option>
        <option value="N"<?php if($warranty_type=='N') { ?> selected="selected" <?php } ?>>No</option>
		</select></td>		
        <td width="15%" align="right">Add File Name</td>
        <td width="20%"><input type="file" name="add_file" id="add_file"  />
        <input type="hidden" name="add_file1" id="add_file1" value="<?php echo $add_file; ?>"  />
        <a href="uploaded_docs/<?php echo $add_file; ?>" download><?php echo $add_file; ?></a>
        </td>
        <td width="13%" align="right">EMI of Year</td>
        <td><input type="text" name="emi_year" id="emi_year"  value="<?php echo $emi_year; ?>" onkeypress="return isNumberKey(event)" /></td>
</tr>
<tr class="row1">
        <td align="right">Start Date <font color="#FF0000">*</font></td>
        <td><input type="text" name="start_period" id="start_period"  class="datepicker" value="<?php echo ConvertSQLDate($start_period); ?>"></td>   
        <td align="right">End Date <font color="#FF0000">*</font></td>
        <td><input type="text" name="end_period" id="end_period"  class="datepicker"  value="<?php echo ConvertSQLDate($end_period); ?>" /></td>
        <td colspan="2"></td>
</tr>
</table>
<br>
<h3>Running Capacity</h3>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td width="15%" align="right">Fuel Type</td>
    <td width="20%"><select name="fuel_type" style="width:64%;" id="fuel_type">
        	<option value="0">---Select---</option>	
         <option value="Petrol" <?php if($fule_type=='Petrol'){ ?> selected="selected" <?php } ?> >Petrol</option>	
        	<option value="Diesel" <?php if($fule_type=='Diesel'){ ?> selected="selected" <?php } ?>>Diesel</option>	
        	<option value="Cng" <?php if($fule_type=='Cng'){ ?> selected="selected" <?php } ?>>CNG</option>	
         <option value="Power" <?php if($fule_type=='Power'){ ?> selected="selected" <?php } ?>>Power</option>	
        	</select>
        	<select name="fuel_unit" id="fuel_unit" style="width:33%;">
        <option value="0">Select Fuel Unit</option>
        <?php $sql_unit=DB_query("select * from unitsofmeasure ",$db);
        while($row_sql=DB_fetch_array($sql_unit))
        {
         $t1='';
         if($row_sql['unitid']==$fuel_unit)
          $t1="selected";
         ?>
        <option value="<?php echo $row_sql['unitid']; ?>" <?php echo $t1; ?>><?php echo $row_sql['unitname']; ?></option>
        <?php } ?>
       </select>
        	</td>
	<td width="15%" align="right">Working Hrs</td>
	<td width="20%"><input type="text" name="one_day_capacity" id="one_day"  value="<?php echo $one_day_capacity; ?>" onkeypress="return isNumberKey(event)"/></td>
	<td width="13%" align="right">Working <font color="#FF0000">*</font></td>
	<td><select name="working" id="working" >
	  <option value="0">Select</option>
	  <option value="Y" <?php if($working=='Y') { ?> Selected="selected" <?php } ?> >Yes</option>
	  <option value="N" <?php if($working=='N') { ?> Selected="selected" <?php } ?>>No</option>
	 </select></td>
</tr>
<tr class="row1">
<td align="right">Opening Machine Reading</td>
<td><input type="text" name="average_production_qty" id="average_production_qty" style="width:64%;" value="<?php echo $average_production_qty; ?>"/>
<select name="reading_unit" id="reading_unit" style="width:33%;">
        <option value="0">Select Reading Unit</option>
        <?php $sql_unit=DB_query("select * from unitsofmeasure ",$db);
        while($row_sql=DB_fetch_array($sql_unit))
        {
         $t1='';
         if($row_sql['unitid']==$reading_unit)
          $t1="selected";
         ?>
        <option value="<?php echo $row_sql['unitid']; ?>" <?php echo $t1; ?>><?php echo $row_sql['unitname']; ?></option>
        <?php } ?>
       </select>
</td>
<td align="right">Opening Machine Date</td>
<td><input type="text" name="opening_machine_date" id="opening_machine_date"  class="datepicker" value="<?php echo ConvertSqlDate($manchine_opening_date);?>" /></td>
<td colspan="2"></td>
</tr>
</table>
<br>
<h3>Asset Manager</h3>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td width="15%" align="right"><!--Accounting Group-->Credit Ledger</td>
    <td width="20%"><select name="accounting_group" id="accounting_group"  >
        <option value="0">Select </option>         	
        <?php         
		$sqlassect="select * from accountledger where ledgertype != 'client' AND ledgertype != 'vendor'";
		$sqlquery=DB_query($sqlassect,$db);
		while($row2=DB_fetch_array($sqlquery))
		{
       $z='';
       if($row2['id']==$accounting_group)
        //$z="selected";
        echo $row2['AccountsID'];
       ?>
		<option value="<?php echo $row2['AccountsID']; ?>"<?php if($accounting_group==$row2['AccountsID']) { ?> selected="selected" <?php } ?> ><?php echo $row2['AccountName']; ?></option>	
        <?php } ?>	
        </select></td>
		 <td width="15%" align="right"><!--Depriciation Account GL Link-->Debit Ledger</td>
		 <td width="20%"><select name="depriciation_ac_gl" id="depriciation_ac_gl"  >
          <option value="0">Select </option>       	
         <?php         
		$sqlassect="select * from accountledger where ledgertype != 'client' AND ledgertype != 'vendor'";
		$sqlquery=DB_query($sqlassect,$db);
		while($row2=DB_fetch_array($sqlquery))
		{
     //  $z2='';
      // if($row2['id']==$depriciation_ac_gl)
       // $z2="selected";
       ?>
       <option value="<?php echo $row2['AccountsID']; ?>"<?php if($depriciation_ac_gl==$row2['AccountsID']) {?> selected="selected" <?php } ?> ><?php echo $row2['AccountName']; ?></option>	
        <?php } ?> 	        	
        </select></td>
        <td width="13%" align="right">Sale Status <font color="#FF0000">*</font></td>
        <td><select name="sale_status" id="sale_status" >
          <option value="0">Select</option>
           <option value="S"<?php if($sale_status=='S') { ?> selected="selected" <?php } ?>>Sale</option>
           <option value="NS" <?php if($sale_status=='NS') { ?> selected="selected" <?php } ?>>Not Sale</option>          
         </select></td>
        </tr>
        <tr class="row1">
		<td align="right">Sale Amount</td>
        <td><input type="text" name="sale_amount" id="sale_amount"  value="<?php echo $sale_amount; ?>" onkeypress="return isNumberKey(event)"/></td>
		<td align="right">Sale Date</td>
		<td><input type="text" name="sale_date" id="sale_date"  class="Datepicker" value="<?php echo ConvertSQlDate($sale_date); ?>" /></td>
		<td align="right">Sale Party</td>
	    <td><select name="sale_party" id="sale_party" >
        		<option value="0">Select</option>
         <?php $vendor=DB_query("select id,vendor_name from suppliers",$db);
        	   while($vendor_row=DB_fetch_array($vendor)){
             $p3='';
             if($vendor_row['id']==$sale_party)
              $p3="selected";
             ?>
         <option value="<?php echo $vendor_row['id']; ?>" <?php echo  $p3; ?>><?php echo $vendor_row['vendor_name']; ?></option>	
        <?php } ?>  
        </select></td>
</tr>
<tr class="row1">
		<td align="right">Purchase Amount</td>
        <td><input type="text" name="purchase_amount" id="purchase_amount"  value="<?php echo $purchase_amt; ?> " onkeypress="return isNumberKey(event)"/></td>  
        <td align="right">Purchase Date</td>
	    <td><input type="text" name="purchase_date" id="purchase_date"  class="Datepicker" value="<?php echo ConvertSQLDate($purchase_date); ?>"/></td>
	    <td align="right">Purchase Party</td>
        <td><select name="purchase_party" id="purchase_party" >
        		<option value="0">Select</option>
         <?php $vendor=DB_query("select id,vendor_name from suppliers",$db);
        	   while($vendor_row=DB_fetch_array($vendor)){
              $p2='';
             if($vendor_row['id']==$purchase_party)
              $p2="selected";
             ?>
         <option value="<?php echo $vendor_row['id']; ?>" <?php echo $p2; ?>><?php echo $vendor_row['vendor_name']; ?></option>	
        <?php } ?>  
        </select></td>
</tr>
</table>
<br>
<h3>Nature of Depriciation</h3>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
        <td align="right">As Per Company Act</td>
        <td><select name="dep_as_per_com" id="dep_as_per_com" >
                <option value="0">Select</option>
                <?php 
                $comSql="select b.id as mainId,b.asset_name from tpl_rate_deprications a inner join tpl_rate_deprications_details b on a.id=b.parent_id where a.act='Company Act'";
               $comSqlExec=DB_query($comSql,$db);
               while($rowComp=DB_fetch_array($comSqlExec))
                {
                ?>
                <option value="<?php echo $rowComp['mainId']; ?>"<?php if($dep_as_per_com==$rowComp['mainId']){ echo 'selected'; } else { echo ''; } ?>><?php echo $rowComp['asset_name']; ?></option>
                <?php } ?>
            </select></td>
                <td colspan="4" id="compDetails"><?php if($dep_as_per_com) { ?><table width="100%" cellspacing="0" cellpadding="3" border="0" >
   <!--
    <tr bgcolor="#CCCCCC">
    <td>Code</strong></td>
    <td>Nature &amp; Asset </strong></td>
    <td style="text-align:center;" colspan="2">Single Shift </strong></td>
    <td style="text-align:center;" colspan="2">Double Shift </strong></td>
    <td style="text-align:center;" colspan="2">Triple Shift </strong></td>
    </tr>
    <tr>
    <td bgcolor="#CCC">&nbsp;</td>
    <td bgcolor="#CCC">&nbsp;</td>
    <td bgcolor="#CCC">WDV</strong></td>
    <td bgcolor="#CCC">SLM</strong></td>
    <td bgcolor="#CCC">WDV</strong></td>
    <td bgcolor="#CCC">SLM</strong></td>
    <td bgcolor="#CCC">WDV</strong></td>
    <td bgcolor="#CCC">SLM</strong></td>
  </tr> -->
  <?php 
  $id=$_REQUEST['id'];
$detSql="select * from tpl_rate_deprications_details where id='".$dep_as_per_com."'";
  $sql1=DB_query($detSql,$db);
$numrow=DB_num_rows($sql1);
while($r=DB_fetch_array($sql1))
  {
    ?>
  <tr>
    <td><input type="hidden" name="code[]" style="width:100%;" value="<?php echo $r['code']; ?>" <?php echo $dis; ?>></td>
    <td><input type="hidden" name="asset_name[]" style="width:100%;" value="<?php echo $r['asset_name']; ?>" <?php echo $dis; ?>></td>
    <td><input type="hidden" name="sng_wdv[]" style="width:100%;" value="<?php echo $r['sng_wdv']; ?>" <?php echo $dis; ?>></td>
    <td><input type="hidden" name="sng_slm[]" style="width:100%;" value="<?php echo $r['sng_slm']; ?>" <?php echo $dis; ?>></td>
    <td><input type="hidden" name="dbl_wdv[]" style="width:100%;" value="<?php echo $r['dbl_wdv']; ?>" <?php echo $dis; ?>></td>
    <td><input type="hidden" name="dbl_slm[]" style="width:100%;" value="<?php echo $r['dbl_slm']; ?>" <?php echo $dis; ?>></td>
    <td><input type="hidden" name="tpl_wdv[]" style="width:100%;" value="<?php echo $r['tpl_wdv']; ?>" <?php echo $dis; ?>></td>
    <td><input type="hidden" name="tpl_slm[]" style="width:100%;" value="<?php echo $r['tpl_slm']; ?>" <?php echo $dis; ?>></td>
  </tr>
 <?php } ?>
</table>
    <?php } else { ?><!--Company Act Details --><?php } ?></td>       
        
</tr>
<tr class="row1">
        <td width="15%" align="right">As Per Income Act</td>
        <td width="20%"><select name="dep_as_per_inc" id="dep_as_per_inc" >
                <option value="0">Select</option>
                <?php 
                $comSql="select b.id as mainId,b.asset_name from tpl_rate_deprications a inner join tpl_rate_deprications_details b on a.id=b.parent_id where a.act='Income Act'";
               $comSqlExec=DB_query($comSql,$db);
               while($rowComp=DB_fetch_array($comSqlExec))
                {
                ?>
                <option value="<?php echo $rowComp['mainId']; ?>"<?php if($dep_as_per_inc==$rowComp['mainId']){ echo 'selected'; } else { echo ''; } ?>><?php echo $rowComp['asset_name']; ?></option>
                <?php } ?>
            </select></td>
            <td width="15%" align="right">Net WDV</td>
		    <td width="20%"><input name="net_wdv" type="text" id="net_wdv"  value="<?php echo $net_wdv; ?>"></td>
		    <td width="13%" align="right">Net WDV Date</td>
		    <td><input name="net_wdv_date" class="datepicker"  id="net_wdv_date" value="<?php echo ConvertSQLDate($net_wdv_date); ?>" readonly></td>
		               <?php if($dep_as_per_inc) { ?>
                    
<!--<tr bgcolor="#CCCCCC">
    <td>Code</strong></td>
    <td>Nature &amp; Asset </strong></td>
    <td style="text-align:center;">Rate</strong></td>
    </tr> -->
    <?php
    $sql_child=DB_query("select * from tpl_rate_deprications_details
      where id='".$dep_as_per_inc."'",$db);
    $numrow1=DB_num_rows($sql_child);
    while($r2=DB_fetch_array($sql_child))
    {
      ?>    
    <input type="hidden" name="code[]" style="width:100%;" value="<?php echo $r2['code']; ?>" <?php echo $dis1; ?> >
    <input type="hidden" name="asset_name[]" style="width:100%;" value="<?php echo $r2['asset_name']; ?>">
    <input type="hidden" name="rate[]" style="width:100%;" value="<?php echo $r2['rate']; ?>" <?php echo $dis1; ?> >
   
    <?php } ?>
    <?php } else { ?><!--Income Act Details --><?php } ?>           
</tr>
<tr class="row1">
        <td align="right">Accumulative Depriciation Amt.</td>
        <td><input type="text" name="accumlative_depriciation_dep" id="accumlative_depriciation_dep"  value="<?php echo $accumlative_depriciation_dep; ?>"/></td>
        <td align="right">Accumulative Depriciation Date</td>
        <td><input type="text" name="accum_date" id="accum_date"  class="datepicker" value="<?php echo ConvertSQLDate($accum_date); ?>" readonly/></td>
        <td align="right">Life 0f Assets</td>
        <td><input type="text" name="asset_life" id="asset_life"  value="<?php echo $asset_life; ?>"/></td>       
</tr>
</table>
<br>
<h3>Location</h3>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
        <td width="15%" align="right">Branch <font color="#FF0000">*</font></td>
        <td width="20%"><select name="location" id="location" >
    <option value="0">Select</option>
     <?php 
		$site_sql = "Select loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' ";
		$site_result = DB_query($site_sql,$db);
		while($site_row = DB_fetch_array($site_result))
		{
       $l='';
       if($site_row['loccode']==$location)
        $l="selected";
		?>
         <option value="<?php echo $site_row['loccode']; ?>" <?php echo $l; ?> ><?php echo $site_row['locationname']; ?></option>
            <?php } ?>
    </select></td>
	<td width="15%" align="right">Installation By</td>
	<td width="20%"><input type="text" name="installation_by" id="installation_by"   value="<?php echo $insatallation_by; ?>"/></td>   
	<td width="13%" align="right">Capitalization Date <font color="#FF0000">*</font></td>
	<td><input type="text" name="date" id="date"  class="datepicker"  value="<?php echo ConvertSQLDate($date); ?>" /></td>
</tr>
<tr class="row1">
    <td align="right">Location</td>
    <td><input type="text" name="loc" id="loc"  value="<?php echo $loc; ?>" /></td>
    <td align="right">Working <font color="#FF0000">*</font></td>
        <td><select name="work_location" id="work_location" >
    <option value="0">Select</option>
     <?php 
		$site_sql = "Select loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$site_result = DB_query($site_sql,$db);
		while($site_row = DB_fetch_array($site_result))
		{
       $l='';
       if($site_row['loccode']==$work_location)
        $l="selected";
		?>
         <option value="<?php echo $site_row['loccode']; ?>" <?php echo $l; ?> ><?php echo $site_row['locationname']; ?></option>
            <?php } ?>
    </select></td>
    <td colspan="2">&nbsp;</td>        
</tr>
<tr class="row1">
    <td align="right">Comment</td>
    <td><textarea name="comment" id="comment" rows="5" cols="20" style="height:60px;"><?php echo $comment;?></textarea></td>
    <td colspan="4">&nbsp;</td>
</tr>
</table>
<p align="center"><input type="submit" value="<?php if($_REQUEST['action']=='edit') echo 'Update'; else echo 'Save'; ?>" name="<?php if($_REQUEST['action']=='edit') echo 'update'; else echo 'Save'; ?>" class="search" onclick="return validate()" /></p>
</form>
</div>
</div>
<script>
function Showasset_type(str)
{
	if(str=='SA')
	{
		document.getElementById("asset_title").style.display="block";
		document.getElementById("asset").style.display="block";
	}
	else
	{
		document.getElementById("asset_title").style.display="none";	
		document.getElementById("asset").style.display="none";	
	}
}
function showCompDetails(str, flag)
{
	//alert(str);
if (str.length==0)
  {
  document.getElementById("compDetails").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        if(flag=='Company Act')
            {
            document.getElementById("compDetails").innerHTML=xmlhttp.responseText;
            }
            else
                {
                    document.getElementById("compDetails1").innerHTML=xmlhttp.responseText;
                }
    }
  }
xmlhttp.open("GET","show_com_act_details.php?id="+str+"&flg="+flag,true);
xmlhttp.send();
}

function isNumber(evt)
 {
    evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
     {
        return false;
    }

    return true;
}

function validate()
{
	
  if(document.getElementById("asset_type").value=='0')
   {
    alert("Please Select Asset Type");
    return false;
   }

   if(document.getElementById("code_name").value=='')
   {
    alert("Please Enter Asset Code");
    return false;
   }


   if(document.getElementById("under_group").value=='0')
   {
    alert("Please Select Asset Group ");
    return false;
   }

    if(document.getElementById("name").value=='')
   {
    alert("Please Select Asset Name ");
    return false;
   } 


    if(document.getElementById("location").value=='0')
   {
    alert("Please Select Branch Name");
    return false;
   } 

    if(document.getElementById("work_location").value=='0')
   {
    alert("Please Select Working Branch");
    return false;
   } 
   
    if(document.getElementById("start_period").value=='//')
   {
    alert("Please Select Start Period");
    return false;
   } 

    if(document.getElementById("end_period").value=='//')
   {
    alert("Please Select End Period");
    return false;
   } 
   if(document.getElementById("working").value=='0')
   {
    alert("Please Select Working");
    return false;
   } 

    if(document.getElementById("sale_status").value=='0')
   {
    alert("Please Select Sale Status");
    return false;
   } 
  
  

    if(document.getElementById("date").value=='//')
   {
    alert("Please Select Capitalization Date");
    return false;
   } 

   return true;

}

  function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : evt.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       }


function GetAssets(str)
{
	     var type = document.getElementById("asset_type").value;
        //var group = document.getElementById("under_group").value;
        //alert(str);
        
	//var site = document.getElementById("site").value;
      if(type=='SA')
      {
			if (window.XMLHttpRequest)
			{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
			}
			else
			{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange=function()
			{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
		           // alert(xmlhttp.responseText);
			document.getElementById("asset").innerHTML=xmlhttp.responseText;
			}
			}
			
			xmlhttp.open("GET","GetAsset_master.php?group="+str,true);
			xmlhttp.send();
	}		
}
	
</script>
    