
<!---------------------------------- cloning start for Accreditation --------------------------------------------->
	<?$mpe=2;?>
<div class="col-sm-12 col-lg-12 col-12" id="raw_materials_div_to_clone" style="display:none;"><br>
		<div class="row">
			<div class="col-sm-2"> 
				<label class="control-label hide" for="Type">&nbsp;<em></em></label> 
				<? $gsi->getRawMaterialTypeList("type_id[]", "", "100%", false, "form-control type_clone type_id type_id", "required"); ?>
				<i class="fas fa-sync-alt fa-spin" style="display:none;font-size:12px;" id="raw_material_load"></i>
			</div>
			<div class="col-sm-2"> 
				<label class="control-label hide" for="Description">&nbsp;<em></em></label> 
				<input type="text" class="form-control description" id="description" name="description[]" value="" placeholder="Description" autocomplete="off" style="background-color: #FFFFE0;font-size:12px;"oninput="this.value=this.value.toUpperCase();">  
			</div>
			<div class="col-sm-1"> 
				<label class="control-label hide" for="Spec">&nbsp;<em></em></label> 
				<input type="text" class="form-control spec" id="spec" name="spec[]" value="" placeholder="Spec" autocomplete="off"oninput="this.value=this.value.toUpperCase();">  
			</div>
			<div class="col-sm-1"> 
				<label class="control-label hide" for="Grade">&nbsp;<em></em></label> 
				<input type="text" class="form-control grade" id="grade" name="grade[]" value="" placeholder="Grade" autocomplete="off"oninput="this.value=this.value.toUpperCase();"> 
			</div>
			<div class="col-sm-1"> 
				<label class="control-label hide" for="Format">&nbsp;<em></em></label> 
				<input type="text" class="form-control format" id="format" name="format[]" value="" placeholder="Format" autocomplete="off" style="background-color: #FFFFE0;"oninput="this.value=this.value.toUpperCase();"> 
			</div>
			<div class="col-sm-1"> 
				<label class="control-label hide" for="Density">&nbsp;<em></em></label> 
				<input type="number" class="form-control density" id="density" name="density[]" value="" placeholder="Density" autocomplete="off" style="background-color: #FFFFE0;"oninput="this.value=this.value.toUpperCase();"> 
			</div>
			<div class="col-sm-2"> 
				<label class="control-label hide" for="MPE">&nbsp;<em></em></label>  
				<? $gsi->getYesNo("mpe[]", "$mpe", "100%", false, "form-control mpe mpe"); ?>
			</div>
			<div class="col-sm-2"> 
				<label class="control-label hide" for="Supplier">&nbsp;<em></em></label> 
				<input type="text" class="form-control supplier" id="supplier" name="supplier[]" value="" placeholder="Supplier" autocomplete="off"oninput="this.value=this.value.toUpperCase();"> 
			</div><br><br>
			<div class="col-sm-2"> 
				<label class="control-label hide" for="Length (mm)">&nbsp;<em></em></label> 
				<input type="number" class="form-control length" id="length" name="length[]" value="" placeholder="Length (m)" autocomplete="off" step="0.01"oninput="this.value=this.value.toUpperCase();">  
			</div>
			<div class="col-sm-1"> 
				<label class="control-label hide" for="Width (mm)">&nbsp;<em></em></label> 
				<input type="number" class="form-control width" id="width" name="width[]" value="" placeholder="Width (m)" autocomplete="off" step="0.01"oninput="this.value=this.value.toUpperCase();">  
			</div>
			<div class="col-sm-1"> 
				<label class="control-label hide" for="Thickness">&nbsp;<em></em></label> 
				<input type="number" class="form-control thickness" id="thickness" name="thickness[]" value="" placeholder="Thickness" autocomplete="off" step="0.01"oninput="this.value=this.value.toUpperCase();">  
			</div>
			<div class="col-sm-1"> 
				<label class="control-label hide" for="MKS(Makes)">&nbsp;<em></em></label> 
				<input type="number" class="form-control mks" id="mks" name="mks[]" value="" placeholder="MKS(Makes)" autocomplete="off" step="0.01"oninput="this.value=this.value.toUpperCase();">  
			</div>
			<div class="col-sm-1"> 
				<label class="control-label hide" for="Gross">&nbsp;<em></em></label> 
				<input type="number" class="form-control gross" id="gross" name="gross[]" value="" placeholder="Gross" autocomplete="off" readonly oninput="this.value=this.value.toUpperCase();"> 
			</div>
			<div class="col-sm-1"> 
				<label class="control-label hide" for="Nett">&nbsp;<em></em></label> 
				<input type="number" class="form-control nett" id="nett" name="nett[]" value="" placeholder="Nett" autocomplete="off" readonly oninput="this.value=this.value.toUpperCase();">  
			</div>
			<div class="col-sm-1"> 
				<label class="control-label hide" for="Scrap (%)">&nbsp;<em></em></label> 
				<input type="number" class="form-control scrap_percent" id="scrap_percent" name="scrap_percent[]" value="" placeholder="Scrap (%)" autocomplete="off" step="0.01"oninput="this.value=this.value.toUpperCase();"> 
			</div>
			<div class="col-sm-1"> 
				<label class="control-label hide" for="UOM">&nbsp;<em></em></label> 
				<input type="text" class="form-control uom" id="uom" name="uom[]" value="" placeholder="UOM" autocomplete="off" style="background-color: #FFFFE0;"oninput="this.value=this.value.toUpperCase();"> 
			</div>
			<div class="col-sm-1"> 
				<label class="control-label hide" for="Price UOM">&nbsp;<em></em></label> 
				<input type="number" class="form-control price_uom" id="price_uom" name="price_uom[]" value="" placeholder="Price UOM" autocomplete="off" step="0.01"oninput="this.value=this.value.toUpperCase();">
			</div>
			<div class="col-sm-1"> 
				<label class="control-label hide" for="Unit Cost">&nbsp;<em></em></label> 
				<input type="number" class="form-control unit_cost" id="unit_cost" name="unit_cost[]" value="" placeholder="Unit Cost" autocomplete="off" readonly oninput="this.value=this.value.toUpperCase();"> 
			</div>
			<div class="col-sm-1"> 
				<label class="control-label hide" for="Scrap Value">&nbsp;<em></em></label> 
				<input type="number" class="form-control raw_scrap_value" id="raw_scrap_value" name="raw_scrap_value[]" value="" placeholder="Scrap Value" autocomplete="off" readonly oninput="this.value=this.value.toUpperCase();">
			</div>

			<div class="col-sm-12" >
				<div class="custom-trash "style="margin-top:0px; float:right;"> 
					<label class="control-label"></label> 
					<span class="fa fa-trash delete_new_raw_materials" alt="" style="color: red;"></span>
				</div>
			</div>
		</div>
	</div>	
<!----------------------------------- Cloning end for Accreditation  --------------------------------------------->

        <section class="content">
			<!-- general form elements -->
                <form class="" method="post" name="rawForm" id="rawForm" action="index?page=view_quotation_progress&action=insert_raw_materials" onsubmit="return validateForm(this)" enctype="multipart/form-data">
					  <div class="row">
						  <div class="col-lg-12 col-sm-12">
						  <div class="form-section mt-2">
							<? 
								$raw_material_query = "SELECT * FROM quot_raw_materials WHERE quot_id='".$_REQUEST['id']."' ";
								$raw_material_sql=mysqli_query($conn,$raw_material_query);
								$raw_material_result=mysqli_num_rows($raw_material_sql);
								if($raw_material_result>0){
									$j = 0;
									while($mapp_row = mysqli_fetch_array($raw_material_sql)){
							?>
							<div class="col-sm-12 col-lg-12 col-12 initial_row_for_raw_materials" id="new_raw_material<?=$mapp_row['id'];?>" data-personal_count="<?=$mapp_row['id'];?>" alt="<?=$mapp_row['id'];?>">
							<div class="row">
							<div class="col-sm-2"> 
								<label class="control-label" for="Type">Type<em></em></label> 
								<? $gsi->getRawMaterialTypeList("type_id[$j]",$mapp_row['type_id'],"100%",false,"form-control select2 type_id","required");?>
                                 <i class="fas fa-sync-alt fa-spin" style="display:none;font-size:12px;" id="raw_material_load"></i>								
							</div>

							<div class="col-sm-2"> 
								<label class="control-label" for="Description">Description<em></em></label> 
								<input type="text" class="form-control description" id="description" name="description[<?=$j;?>]" value="<?php echo $mapp_row['description'];?>" placeholder="Description" style="background-color: #FFFFE0;font-size:12px;"oninput="this.value=this.value.toUpperCase();">
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Spec">Spec<em></em></label> 
								<input type="text" class="form-control spec" id="spec" name="spec[<?=$j;?>]" value="<?php echo $mapp_row['spec'];?>" placeholder="Spec" oninput="this.value=this.value.toUpperCase();">
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Grade">Grade<em></em></label> 
								<input type="text" class="form-control grade" id="grade" name="grade[<?=$j;?>]" value="<?php echo $mapp_row['grade'];?>" placeholder="Grade"oninput="this.value=this.value.toUpperCase();">
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Format">Format<em></em></label> 
								<input type="text" class="form-control format" id="format" name="format[<?=$j;?>]" value="<?php echo $mapp_row['format'];?>" placeholder="Format" style="background-color: #FFFFE0;"oninput="this.value=this.value.toUpperCase();">
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Density">Density<em></em></label> 
								<input type="number" class="form-control density" id="density" name="density[<?=$j;?>]" value="<?php echo $mapp_row['density'];?>" placeholder="Density" style="background-color: #FFFFE0;"oninput="this.value=this.value.toUpperCase();">
							</div>

							<div class="col-sm-2"> 
								<label class="control-label" for="MPE">M.O.E<em></em></label> 
								<? $gsi->getYesNo("mpe[$j]",$mapp_row['mpe'], "100%", false, "form-control mpe"); ?>
							</div>

							<div class="col-sm-2"> 
								<label class="control-label" for="Supplier">Supplier<em></em></label> 
								<input type="text" class="form-control supplier" id="supplier" name="supplier[<?=$j;?>]" value="<?php echo $mapp_row['supplier'];?>" placeholder="Supplier" >
							</div>

							<div class="col-sm-2"> 
								<label class="control-label" for="Length (mm)">Length (m)<em></em></label> 
								<input type="number" class="form-control length" id="length" name="length[<?=$j;?>]" value="<?php echo $mapp_row['length'];?>" placeholder="Length (m)" step="0.01" oninput="this.value=this.value.toUpperCase();">
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Width (mm)">Width (m)<em></em></label> 
								<input type="number" class="form-control width" id="width" name="width[<?=$j;?>]" value="<?php echo $mapp_row['width'];?>" placeholder="Width (m)" step="0.01"oninput="this.value=this.value.toUpperCase();">
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Thickness">Thickness(mm)<em></em></label> 
								<input type="number" class="form-control thickness" id="thickness" name="thickness[<?=$j;?>]" value="<?php echo $mapp_row['thickness'];?>" placeholder="Thickness" step="0.01"oninput="this.value=this.value.toUpperCase();">
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="MKS(Makes)">MKS(Makes)<em></em></label> 
								<input type="number" class="form-control mks" id="mks" name="mks[<?=$j;?>]" value="<?php echo $mapp_row['mks'];?>" placeholder="MKS(Makes)" step="0.01"oninput="this.value=this.value.toUpperCase();">
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Gross">Gross<em></em></label> 
								<input type="number" class="form-control gross" id="gross" name="gross[<?=$j;?>]" value="<?php echo $mapp_row['gross'];?>" placeholder="Gross" readonly oninput="this.value=this.value.toUpperCase();">
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Nett">Nett<em></em></label> 
								<input type="number" class="form-control nett" id="nett" name="nett[<?=$j;?>]" value="<?php echo $mapp_row['nett'];?>" placeholder="Nett" readonly oninput="this.value=this.value.toUpperCase();">
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Scrap (%)">Scrap (%)<em></em></label> 
								<input type="number" class="form-control scrap_percent" id="scrap_percent" name="scrap_percent[<?=$j;?>]" value="<?php echo $mapp_row['scrap_percent'];?>" placeholder="Scrap (%)" step="0.01" oninput="this.value=this.value.toUpperCase();">
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="UOM">UOM<em></em></label> 
								<input type="text" class="form-control uom" id="uom" name="uom[<?=$j;?>]" value="<?php echo $mapp_row['uom'];?>" placeholder="UOM" style="background-color: #FFFFE0;" oninput="this.value=this.value.toUpperCase();">
							</div>
							<div class="col-sm-1"> 
								<label class="control-label" for="Price UOM">Price UOM<em></em></label> 
								<input type="number" class="form-control price_uom" id="price_uom" name="price_uom[<?=$j;?>]" value="<?php echo $mapp_row['price_uom'];?>" placeholder="Price UOM" step="0.01" oninput="this.value=this.value.toUpperCase();">
							</div>
	
							<div class="col-sm-1"> 
								<label class="control-label" for="Unit Cost">Unit Cost<em></em></label> 
								<input type="number" class="form-control unit_cost" id="unit_cost" name="unit_cost[<?=$j;?>]" value="<?php echo $mapp_row['unit_cost'];?>" placeholder="Unit Cost" readonly oninput="this.value=this.value.toUpperCase();">
							</div>
							
							<div class="col-sm-1"> 
								<label class="control-label" for="Scrap Value">Scrap Value<em></em></label> 
								<input type="number" class="form-control raw_scrap_value" id="raw_scrap_value" name="raw_scrap_value[<?=$j;?>]" value="<?php echo $mapp_row['raw_scrap_value'];?>" placeholder="Scrap Value" readonly oninput="this.value=this.value.toUpperCase();">
							</div>
							
                      
							<div class="col-sm-12" style="margin-top:0px;"> 
								<div class="custom-trash" style="float:right;">
									<label class="control-label"></label>
									<input type="hidden" name="raw_material_mapping_id[<?=$j;?>]" value="<?php echo $mapp_row['id'];?>">
									
									<?php if ($j != 0) { ?>
									<span class="fa fa-trash delete_new_raw_materials" style="cursor:pointer; color: red;"  alt="<?php echo $mapp_row['id'];?>"></span>
									<?php } ?>
									<i class="fas fa-sync-alt fa-spin" id="load_new_raw_materials<?=$mapp_row['id'];?>" style="font-size: 20px;display:none;"></i>
									<i class="fa fa-check" id="status_update_personal_done_<?=$mapp_row['id'];?>" style="color:#bad23a;font-size: 20px;display:none;"></i>
								</div>
							</div>
						
						</div>
					 <hr style="background-color: #9c4893; height:1px; margin-top: 2; margin-bottom: 2;">
					</div>

					<?
					$j++;
					}}else{?>
					<div class="col-sm-12 col-lg-12 col-12 initial_row_for_raw_materials" id="new_raw_material0" data-personal_count="0" alt="0">
						<div class="row">
							<div class="col-sm-2"> 
								<label class="control-label" for="Type">Type<em></em></label> 
								<? $gsi->getRawMaterialTypeList("type_id[]","","100%",false,"form-control select2 type_id","required"); ?>
                                								
                                <i class="fas fa-sync-alt fa-spin" style="display:none;font-size:12px;" id="raw_material_load"></i>								
							</div>

							<div class="col-sm-2"> 
								<label class="control-label" for="Description">Description<em></em></label> 
								<input type="text" class="form-control description" id="description" name="description[]" value="" placeholder="Description" autocomplete="off" style="background-color: #FFFFE0;font-size:12px;">  
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Spec">Spec<em></em></label> 
								<input type="text" class="form-control spec" id="spec" name="spec[]" value="" placeholder="Spec" autocomplete="off">  
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Grade">Grade<em></em></label> 
								<input type="text" class="form-control grade" id="grade" name="grade[]" value="" placeholder="Grade" autocomplete="off">  
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Format">Format<em></em></label> 
								<input type="text" class="form-control format" id="format" name="format[]" value="" placeholder="Format" autocomplete="off" style="background-color: #FFFFE0;">  
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Density">Density<em></em></label> 
								<input type="number" class="form-control density" id="density" name="density[]" value="" placeholder="Density" autocomplete="off" style="background-color: #FFFFE0;">  
							</div>

							<div class="col-sm-2"> 
								<label class="control-label" for="MPE">M.O.E<em></em></label>
								<? $gsi->getYesNo("mpe[]","$mpe", "100%", false, "form-control mpe"); ?>
							</div>

							<div class="col-sm-2"> 
								<label class="control-label" for="Supplier">Supplier<em></em></label> 
								<input type="text" class="form-control supplier" id="supplier" name="supplier[]" value="" placeholder="Supplier" autocomplete="off">  
							</div>

							<div class="col-sm-2"> 
								<label class="control-label" for="Length (m)">Length (m)<em></em></label> 
								<input type="number" class="form-control length" id="length" name="length[]" value=""  placeholder="Length (m)" autocomplete="off"step="0.01">  
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Width (mm)">Width (m)<em></em></label> 
								<input type="number" class="form-control width" id="width" name="width[]" value="" placeholder="Width (m)" autocomplete="off" step="0.01">  
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Thickness">Thickness(mm)<em></em></label> 
								<input type="number" class="form-control thickness" id="thickness" name="thickness[]" value="" placeholder="Thickness" autocomplete="off" step="0.01">  
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="MKS(Makes)">MKS(Makes)<em></em></label> 
								<input type="number" class="form-control mks" id="mks" name="mks[]" value="" placeholder="MKS(Makes)" autocomplete="off" step="0.01">  
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Gross">Gross<em></em></label> 
								<input type="number" class="form-control gross" id="gross" name="gross[]" value="" placeholder="Gross" autocomplete="off" readonly>  
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Nett">Nett<em></em></label> 
								<input type="number" class="form-control nett" id="nett" name="nett[]" value="" placeholder="Nett" autocomplete="off" readonly>  
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Scrap (%)">Scrap (%)<em></em></label> 
								<input type="number" class="form-control scrap_percent" id="scrap_percent" name="scrap_percent[]" value="" placeholder="Scrap (%)" autocomplete="off" step="0.01">  
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="UOM">UOM<em></em></label> 
								<input type="text" class="form-control uom" id="uom" name="uom[]" value="" placeholder="UOM" autocomplete="off" style="background-color: #FFFFE0;">  
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Price UOM">Price UOM<em></em></label> 
								<input type="number" class="form-control price_uom" id="price_uom" name="price_uom[]" value="" placeholder="Price UOM" autocomplete="off" step="0.01">  
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Unit Cost">Unit Cost<em></em></label> 
								<input type="number" class="form-control unit_cost" id="unit_cost" name="unit_cost[]" value="" placeholder="Unit Cost" autocomplete="off" readonly>  
							</div>

							<div class="col-sm-1"> 
								<label class="control-label" for="Scrap Value">Scrap Value<em></em></label> 
								<input type="number" class="form-control raw_scrap_value" id="raw_scrap_value" name="raw_scrap_value[]" value="" placeholder="Scrap Value" autocomplete="off" readonly>  
							</div>

						</div>
					</div>
					<?}?>
					<div class="form-group col-sm-12 raw_materials_div_to_append">	
						<label class="add_one_more_raw_materials" style="margin-left:0%;cursor:pointer;color: #a423a4; "><span class="fa fa-plus"></span>Add More</label>
					</div>
							</div>
						
						 </div>
					  </div><!-- /.row -->
                  <div class="card-footer">
					<input type="hidden" id="id" name="id" value="<?php echo $id;?>">
					<input type="hidden" id="quot_id" name="quot_id" value="<?php echo $_REQUEST['id'];?>">
					<input type="hidden" id="from" name="from" value="<?php echo $from;?>">
					<input type="hidden" id="query_string" name="query_string" value="<?php echo $query_string;?>">
					<input type="hidden" id="section_status_raw" name="section_status_raw" value="">
					<button type="button" id="submit_raw_incomplete" class="btn btn-danger" onclick="submitFormRowStatus(1, 'spinner_raw_incomplete')">
						Save Raw Incomplete
						<i class="fas fa-sync-alt fa-spin" style="display:none;" id="spinner_raw_incomplete"></i>
					</button>
					<button type="button" id="submit_raw_completed" class="btn btn-success" onclick="submitFormRowStatus(2, 'spinner_raw_completed')">
						Raw Section Completed
						<i class="fas fa-sync-alt fa-spin" style="display:none;" id="spinner_raw_completed"></i>
					</button>
					<div style="float:right;">
						<button type="button" id="prevButton" class="btn btn-secondary" onclick="ToPrevTab()">Previous</button>
						<button type="button" id="nextButton" class="btn btn-secondary" onclick="ToNextTab()">Next</button>

                   </div>
                  </div>
                </form>
</section>
<script type="text/javascript">
function submitFormRowStatus(status, spinnerId) {
    document.getElementById('section_status_raw').value = status;

    document.querySelectorAll('.fa-spin').forEach(function(spinner) {
        spinner.style.display = 'none';
    });
    document.getElementById(spinnerId).style.display = 'inline-block';
    document.getElementById('rawForm').submit();
}
$(function(){

	
	$('.add_one_more_raw_materials').click(function() {		
		$('#raw_materials_div_to_clone').show();		
		var div_count = $('.initial_row_for_raw_materials').last().attr("data-personal_count");
		div_count++;
		var cloned_div = $('#raw_materials_div_to_clone').clone().addClass("initial_row_for_raw_materials").attr("id","new_raw_material"+div_count).attr("data-personal_count",div_count);		
		$('.raw_materials_div_to_append').before(cloned_div);		
		$('#raw_materials_div_to_clone').hide();
		$('#new_raw_material'+div_count).attr("alt",div_count)
	    $('#new_raw_material'+div_count).children().find(".type_clone").attr("id","type_id"+div_count).attr("alt",div_count).select2();		
	});
	
	
	
	$("#rawForm").on("click", ".delete_new_raw_materials",function() {
	    if(confirm('Are you sure you want to delete?')){		
			if($(this).attr("alt") != ""){
				var raw_material_mapping_id = $(this).attr("alt");
				$('#load_new_raw_materials'+raw_material_mapping_id).show();
				var form_data   = {'raw_material_mapping_id':raw_material_mapping_id};      
                //alert(raw_material_mapping_id);				
				$.ajax({
					async: true,
					type: "POST",
					url: site_url+"/modules/quotation_management/index.php?page=ajax_actions&action=delete_raw_material_mapping",
					//url: site_url+"/client_management/index?page=ajax_actions&action=delete_raw_material_mapping",
					data: form_data,
					success: function(result){    
						var resultObj = jQuery.parseJSON(result); 
						if(resultObj.status == "success"){
							$('#status_update_personal_done_'+raw_material_mapping_id).show();
							$('#load_new_raw_materials'+raw_material_mapping_id).hide();
							
							setTimeout(function() {
								$('#status_update_personal_done_'+raw_material_mapping_id).hide();
								$('#new_raw_material'+raw_material_mapping_id).remove();
								//location.reload();
							},1000);
						}
					}
				});
			}else{
				$(this).parent().parent().parent().parent().remove();
			}
		}
	});
	
	$("#rawForm").on("change",".type_id",function(){
		var div_no = $(this).parent().parent().parent().attr("alt");
		var type_id = $(this).val();
		if(type_id != ""){
			$('#new_raw_material'+div_no).find("#raw_material_load").show();
			var form_data   = {'type_id':type_id};
			$.ajax({
				async: true,
				type: "POST",
				url: site_url+"/modules/quotation_management/index.php?page=ajax_actions&action=get_raw_material_details",
				data: form_data,
				success: function(result){  
					var resultObj = jQuery.parseJSON(result); 
					if(resultObj.status == 1){
						$('#new_raw_material'+div_no).find("#description").val(resultObj.description);
						$('#new_raw_material'+div_no).find("#format").val(resultObj.format);
						//$('#new_raw_material'+div_no).find("#mpe").val(resultObj.mpe);
						$('#new_raw_material'+div_no).find("#mpe").val(resultObj.mpe).trigger("change");
						$('#new_raw_material'+div_no).find("#uom").val(resultObj.uom);
						$('#new_raw_material'+div_no).find("#density").val(resultObj.density);
						$('#new_raw_material'+div_no).find("#raw_material_load").hide();
					}
				}
			});
		}
	});
	
});
</script>
<script>
function calculateGross(row) {
    var length = parseFloat(row.find('.length').val()) || 1; 
    var width = parseFloat(row.find('.width').val()) || 1;
    var thickness = parseFloat(row.find('.thickness').val()) || 1;
    var mks = parseFloat(row.find('.mks').val()) || 1; 
    var density = parseFloat(row.find('.density').val()) || 1;

	var grossAmount = (((length / 1000) * (width / 1000) * thickness) / mks) * density;
 
    row.find('.gross').val(grossAmount.toFixed(5));  
	row.find('.nett').val(grossAmount.toFixed(5));
}
function calculateUnitCost(row) {
    var price_uom = parseFloat(row.find('.price_uom').val()) || 1;
    var nett = parseFloat(row.find('.nett').val()) || 1;
    var scrap_percent = parseFloat(row.find('.scrap_percent').val()) || 1; 

    var unitcost = (price_uom * nett) * (1 + (scrap_percent / 100));
    
    row.find('.unit_cost').val(unitcost.toFixed(2));
}
function calculateScrapvalue(row) {
    var gross = parseFloat(row.find('.gross').val()) || 1;
    var price_uom = parseFloat(row.find('.price_uom').val()) || 1;
    var scrap_percent = parseFloat(row.find('.scrap_percent').val()) || 1; 

    var scrapvalue = (gross * price_uom) * (scrap_percent / 100);
    
    row.find('.raw_scrap_value').val(scrapvalue.toFixed(2));
}


$('#rawForm').on('input', '.density, .width,.type_id, .thickness, .mks, .length, .price_uom, .nett, .scrap_percent, .gross',  function () {
    var row = $(this).closest('.row');  
    calculateGross(row);
	calculateUnitCost(row);
	calculateScrapvalue(row);
});


</script>
