<?php 
$tmp_id=0;
$tmp_th_e=0;
$tmp_sr_id=0;
$vcl_srvs_inv_header=0;
$service_sub_tot=0;
$parts_sub_tot=0;
$technician_sub_tot=0;
$grand_total_sub_tot=0;
$loan_title='';
//$loan_id=8;


?>
<?php $this->load->view("common/header"); ?>
<!-- end: HEAD -->

<!-- start: CSS REQUIRED FOR THIS PAGE ONLY -->
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/select2/select2.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/datepicker/css/datepicker.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-timepicker/css/bootstrap-timepicker.min.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-daterangepicker/daterangepicker-bs3.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-colorpicker/css/bootstrap-colorpicker.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/jQuery-Tags-Input/jquery.tagsinput.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-fileupload/bootstrap-fileupload.min.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/summernote/build/summernote.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>css/jquery-ui.css">
<style type="text/css">
label {
	font-weight: 700;
}
.table > thead:first-child > tr:first-child > th, .table > thead:first-child > tr:first-child > td, .table-striped thead tr.primary:nth-child(2n+1) th {
	background-color:#666;
			    border-color: #666;
			    border-top: 1px solid #666;
			    color: white;
			    text-align: center;
}
.form-horizontal .form-group {
	margin-left: 0;
	margin-right: 0;
}
</style>
<style type="text/css">
label {
	font-weight: 700;
}
.table > thead:first-child > tr:first-child > th, .table > thead:first-child > tr:first-child > td, .table-striped thead tr.primary:nth-child(2n+1) th {
			    background-color: #428bca;
			    border-color: #357ebd;
			    border-top: 1px solid #357ebd;
			    color: white;
			    text-align: center;
			}
.form-horizontal .form-group {
	margin-left: 0;
	margin-right: 0;
}
td {
	font-size: 13px;
}
.radio{
  float: left;
  margin-right: 10px !important;
  margin-top: -4px !important;
}
.col-sm-3 {
  height: 60px;
}
.accessories_header {
  border-bottom: 1px solid #a0a0a4;
  margin-bottom: 10px;
}
.accessories_header div {
  font-size: 14px;
  margin-left: -10px;
  margin-right: -10px;
}
.panel-heading{
	padding-left:15px;
	margin-bottom:15px;
	margin-top:10px;
	
}
</style>

<!-- end: HEAD -->

<!-- start: CSS REQUIRED FOR THIS PAGE ONLY -->
<link rel="stylesheet" type="text/css" href="<?php echo asset_url(); ?>plugins/select2/select2.css" />
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/DataTables/media/css/DT_bootstrap.css" />
<!-- end: CSS REQUIRED FOR THIS PAGE ONLY -->

<!-- start: CSS REQUIRED FOR THIS PAGE ONLY -->
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/select2/select2.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/datepicker/css/datepicker.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-timepicker/css/bootstrap-timepicker.min.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-daterangepicker/daterangepicker-bs3.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-colorpicker/css/bootstrap-colorpicker.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/jQuery-Tags-Input/jquery.tagsinput.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-fileupload/bootstrap-fileupload.min.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/summernote/build/summernote.css">
<!-- end: CSS REQUIRED FOR THIS PAGE ONLY -->

<!-- end: HEAD -->
<!-- start: BODY -->
<body>
<!-- start: HEADER -->
<!-- start: HEADER -->
		<div class="navbar navbar-inverse navbar-fixed-top">
			<!-- start: TOP NAVIGATION CONTAINER -->
			<div class="container">
				<div class="navbar-header">
					<!-- start: RESPONSIVE MENU TOGGLER -->
					<button data-target=".navbar-collapse" data-toggle="collapse" class="navbar-toggle" type="button">
						<span class="clip-list-2"></span>
					</button>
					<!-- end: RESPONSIVE MENU TOGGLER -->
					<!-- start: LOGO -->
					<?php $this->load->view("common/logo"); ?>
					<!-- end: LOGO -->
				</div>
				<div class="navbar-tools">
					<!-- start: TOP NAVIGATION MENU -->
				<?php $this->load->view("common/notifications.php"); ?>
					<!-- end: TOP NAVIGATION MENU -->
				</div>
			</div>
			<!-- end: TOP NAVIGATION CONTAINER -->
		</div>
		<!-- end: HEADER -->
		<!-- start: MAIN CONTAINER -->
		<div class="main-container">
			<div class="navbar-content">
				<!-- start: SIDEBAR -->
				<?php $this->load->view("common/navigation"); ?>
				<!-- end: SIDEBAR -->
			</div>
			<!-- start: PAGE -->
			<div class="main-content">
				<!-- end: SPANEL CONFIGURATION MODAL FORM -->
				<div class="container">
					<!-- start: PAGE HEADER -->
					<div class="row">
						<div class="col-sm-12">
							<!-- start: PAGE TITLE & BREADCRUMB -->
							<ol class="breadcrumb">
								<li>
									<a href="#">
										 Dashboard 
									</a>
								</li>
                                
								<li>
									<a href="<?php echo base_url('service'); ?>">
										Service
									</a>
								</li>

								<li class="active">
										Add Service
								</li>

								<li class="search-box">
									<form class="sidebar-search">
										<div class="form-group">
											<input type="text" placeholder="Start Searching...">
											<button class="submit">
												<i class="clip-search-3"></i>
											</button>
										</div>
									</form>
								</li>
							</ol>
							<div class="page-header">
								<h1><?php if ($service_id) echo 'Update'; else 'Add'; ?> Service </h1>
							</div>
<?php //print_r($service_details);?>
                            <p>Please fill in the information below. The field labels marked with * are required input fields.</p>
						</div>
					</div>
					<!-- end: PAGE HEADER -->
					<!-- start: PAGE CONTENT 
                    <!-- start grid -->



                    <div class="row">
                    
						<div class="col-md-12">
                       
							<!-- start: DYNAMIC TABLE PANEL -->
							<div class="panel panel-default">
								<div class="panel-heading" style="margin-top:0px; margin-bottom:0">
									<i class="fa fa-plus"></i>
									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add Service
								</div>
								<div class="panel-body">
                            <div class="alert alert-danger" style="display:none;">
                                <button class="close" data-dismiss="alert">
                                    ×
                                </button>
                                <i class="fa fa-times-circle"></i>
                                <strong></strong> <span class="errortxt"></span>
                            </div>
                         <div class="alert alert-success" style="display:none;">
                                <button class="close" data-dismiss="alert">
                                    ×
                                </button>
                                <i class="fa fa-check-circle"></i>
                                <strong></strong><span class="succetxt"></span>
                            </div> 
                            
                            
                                
                                
                   		<form role="form" class="form-horizontal" id="create_service_form" action="#" method="post">
                        
                        <div class="col-md-12"></div><!--col-md-12-->
                        <div class="col-md-12">
                                  
                                    
                     
                       <!-- <div class="col-md-4">
                            <div class="form-group">
                                <label>Serial No</label>
                                
                                <input type='text' class="form-control" id="qts_reference_no" name="qts_reference_no" value="" readonly/>
                            </div>
                        </div>
-->
                                        
										
                                        

                                        <div class="">
											<div class="">
												
													<div class="">
	
    <div class="panel-heading" style="font-weight: 700;">Item Details</div>													

<div class="col-sm-3">

<div class="form-group">

<label>Warehouse * </label>
<select id="warehouse_id" class="form-control" name="warehouse_id">

<!--<option value="">-- Select Warehouse --</option>-->

<?php 

$ss_warehouse_id=$this->session->userdata('ss_warehouse_id'); 

foreach ($warehouse_list as $row)

{

$sel='';

if($service_details->warehouse_id==$row->id)
{
$sel=' selected="selected"';
}else if($ss_warehouse_id==$row->id){
$sel=' selected="selected"';
}

?>  



<option <?php echo $sel;?> value="<?php echo $row->id; ?>">

<?php echo $row->name; ?>

</option>

<?php }?>



</select>



</div>

</div> 
<div class="col-md-3">
<div class="form-group">
<label>Item Avalable Showroom/Customer* </label><?php //print_r($suppliers);?>
<select id="service_item_avalable" class="form-control" name="service_item_avalable">
<option value="">-- Select --</option>
<option  value="Showroom" <?php if(isset($service_details->service_item_avalable)&& $service_details->service_item_avalable=='Showroom'){echo 'selected';}  ?>>Showroom</option>
<option value="Customer" <?php if(isset($service_details->service_item_avalable)&& $service_details->service_item_avalable=='Customer'){echo 'selected';}  ?>>Customer</option>
<option value="Repair" <?php if(isset($service_details->service_item_avalable)&& $service_details->service_item_avalable=='Repair'){echo 'selected';}  ?>>Repair</option>
</select>
</div>
</div>
                                                        

<div class="col-md-3">
                            <div class="form-group">
															<label>Type  * </label><?php //print_r($suppliers);?>
                                                          <select id="service_type" class="form-control" name="service_type">
                                                                  <option value="">-- Select --</option>
<option value="Serial" <?php if(isset($service_details->service_type)&& $service_details->service_type=='Serial'){echo 'selected';}  ?>>Serial No</option>
<option value="Invoice" <?php if(isset($service_details->service_type)&& $service_details->service_type=='Invoice'){echo 'selected';}  ?>>Invoice No</option>

<option value="Repair" <?php if(isset($service_details->service_type)&& $service_details->service_type=='Repair'){echo 'selected';}  ?>>Repair</option>
																		
																	</select>
                                                             
														</div></div> 
                                                       
                                                        
                                                        
 <div class="col-md-12">&nbsp;</div>                                                         
                                                        
                                                        
                                                        
<div class="col-sm-3" style="margin-bottom:10px; <?php if (empty($service_details->service_type)) echo ""; else if($service_details->service_type=='Repair') echo 'display:none'?> " id="repair_hide">
                                                      	<div class="form-group">
                                                      
                                                        
<div id="search_by_sn_details" style=" <?php if (empty($service_details->service_type)) echo "display:block"; else if($service_details->service_type!='Serial') echo 'display:none'?> ">                                                        
                                                        
                                                        <?php //print_r($product_list);?>
                                                        <?php //echo "product id:".$service_details->product_id ?>
															<label for="customer_id">Product Serial No.* </label><!---->
                                                       
															<!--<select id="product_sn" class="form-control search-select" name="product_sn" onChange="check_product_details()">								                               <option value="">-- Select Serial No. --</option>
                                                                <?php foreach ($product_list as $row){
$set='';	
if (isset($service_details->product_sn) && $row->pis_number==$service_details->product_sn){
		$set = 'selected';
		}
?> 
<option <?php echo $set ?> value="<?php echo $row->sis_number;?>"><?php echo $row->product_name;?> (<?php echo $row->product_code;?>) Sn.: <?php echo $row->sis_number;?> </option>
															 <?php }  ?>
								                             </select>-->
<input type="hidden" id="product_sn"  name="product_sn" class="js-data-product-sn-ajax form-control" style="padding:0px 0px; border: none; box-shadow: none" placeholder="-Select Serial No.-"  onChange="check_product_details()"/>                                                             
                                                             
 </div> <!--end search_by_sn_details-->  
 
 
 <div id="search_by_invoice_details" style=" <?php if (empty($service_details->service_type)) echo "display:none"; else if($service_details->service_type!='Invoice') echo 'display:none'?> ">                                                        
                                                        
                                                        <?php //print_r($sales_list);?>
                                                        <?php //echo "type :".$service_details->service_type ?>
															<label for="customer_id">Invoice No.* </label><!---->
                                                       
															<select id="sale_id" class="form-control search-select" name="sale_id" >								                               <option value="">-- Select Invoice No. --</option>
                                                                <?php foreach ($sales_list as $row){
$set='';	
if (isset($service_details->sale_id) && $row['sale_id']==$service_details->sale_id){
		$set = 'selected';
		}
?> 
<option <?php echo $set ?> value="<?php echo $row['sale_id'];?>"><?php echo $row['sale_reference_no'];?> </option>
															 <?php }  ?>
								                             </select>
 </div> <!--end search_by_invoice_details--> 
 
 
                                                        
      <img id="lording-gif" src="<?php echo asset_url(); ?>images/loading.gif" style="display:none; float: left; margin-left: 12px; margin-top: 12px; position: absolute;" >
      
      
      
      
      
      
      
      
      
   
                                                             
									</div>	
                                    </div>	
                                    
   <div class="col-sm-3" id="sn_item_name">
                                                      	<div class="form-group">
                                                        <div style="width:100%; height:3px">&nbsp;</div>
                                                        <?php //echo "cus id:".$service_details->service_customer_id ?>
															<label for="customer_id">Product Details  </label><!--search-select-->
   <?php //print_r($product_list);?>  
   <?php //echo $service_details->product_sn ?>
<div id="item_details"> 
Select Serial No.
</div>  
 <input name="product_id" type="hidden" id="product_id" value="0">
   <div id="product_data">                                                  
	<!--<select id="product_id" class="form-control" name="product_id" onChange="check_product_details()">								                               <option value="">-- Select Item Name --</option>
                                                                <?php foreach ($all_product_list as $row){
$set='';	
	if (isset($service_details->product_id) && $row->product_id==$service_details->product_id){
		$set = 'selected';
		}
?> 

																							   <option <?php echo $set ?> value="<?php echo $row->product_id;?>"><?php echo $row->product_name; ?> (<?php echo $row->product_code; ?>) </option>
															 <?php }  ?>
								                             </select>-->
                                                             </div>
									</div>	
                                    
                                    
                                    				
														</div>  
  <div class="col-md-3" id="rep_item_sn" style=" <?php if (empty($service_details->service_type)) echo "display:none"; else if($service_details->service_type=='Repair') echo 'display:block'?> ">
<div class="form-group">

<label>Repair Item Serial No.  * </label>
<input name="service_rep_item_sn" type="text" class="form-control" id="service_rep_item_sn" value="<?php if (!empty($service_details->service_rep_item_sn)) echo $service_details->service_rep_item_sn ?>">
</div></div>                                                          
  <div class="col-md-3" id="rep_item_name" style=" <?php if (empty($service_details->service_type)) echo "display:none"; else if($service_details->service_type=='Repair') echo 'display:block'?> ">
<div class="form-group">

<label>Repair Item Name  * </label>
<input name="service_rep_item_name" type="text" class="form-control" id="service_rep_item_name" value="<?php if (!empty($service_details->service_rep_item_name)) echo $service_details->service_rep_item_name ?>"> 
</div></div>                                                      
                                                         
   
                                    
                                    
                                   <!-- <div class="col-sm-12" style="margin-bottom:10px">			
                                    
														</div> -->
                                                        
                                                                                                              
                                                        
                                                        <div class="col-sm-3">
                                                      	<div class="form-group">
                                                        <?php //echo "cus id:".$service_details->service_customer_id ?>
															<label for="customer_id">Customer * </label><!--search-select-->
                                                       
<!--<select id="service_customer_id" class="form-control search-select" name="service_customer_id" onChange="show_waking_cus_details(this.value)">								                               <option value="">-- Select Customer --</option>
                                                                <?php foreach ($customer_list as $row){
$set='';	
	if (isset($service_details->service_customer_id) && $row['cus_id']==$service_details->service_customer_id){
		$set = 'selected';
		}
?> 
																							   <option <?php echo $set ?> value="<?php echo $row['cus_id'];?>"><?php echo $row['cus_name']; if($row['cus_phone']) echo " / ".$row['cus_phone'];?>  </option>
															 <?php }  ?>
								                             </select>-->
                                                             
<input type="hidden" id="service_customer_id" name="service_customer_id" class="js-data-customer_id-ajax form-control" style="padding:0px 0px; border: none; box-shadow: none" placeholder="-Select Customer-" />  
<br>

<a id="modal_ajax_easy_ref_customers_btn_quatation" name="customer" style="cursor:pointer;"><i style="background-color: #428bca;
float: left;
margin-left: 7px;
margin-top: 5px;
color: #fff;
padding: 5px;
border-radius: 6px;" class="" id="addIcon">Create</i></a>                            
                                                             
									</div>					
														</div>
                                                        
                                                        
<div class="col-md-3" id="service_walking_cus_name_wap" style="display:none">
    <div class="form-group">
    	<label>Walking Customer Name </label>
    	<input value="<?php if (!empty($service_details->service_walking_cus_name)) echo $service_details->service_walking_cus_name ?>" name="service_walking_cus_name" type="text" class="form-control" id="service_walking_cus_name">
    </div>
</div>

<div class="col-md-3" id="service_walking_cus_phone_wap" style="display:none">
    <div class="form-group">
    	<label>Walking Customer Phone </label>
    	<input value="<?php if (!empty($service_details->service_walking_cus_phone)) echo $service_details->service_walking_cus_phone ?>" name="service_walking_cus_phone" type="text" class="form-control" id="service_walking_cus_phone">
    </div>
</div>
                                                        
                                                     <!-- <div class="col-sm-4">
                                                        <div class="form-group">
                                                        
											<label>
												Service Number
											</label>
											<br/>
												<input type="text" id="service_reference_no" name="service_reference_no" class="form-control"data-bv-field="date" value="<?php if(isset($service_details->service_reference_no)){echo $service_details->service_reference_no;}  ?>">
											</div>
										</div>     -->
                                                        
                                                         <div class="col-md-3" style="display:none">
                            <div class="form-group">
                            <?php // print_r($service_details);
							//echo $service_details->service_datetime;
							
							?>
                                <label>Service Start Date *</label>
                               
                            
                                    <input id="service_datetime" name="service_datetime" type='text' class="form-control date-picker" 
                                    value="<?php if(!$service_id){echo date('m/d/Y');} else echo date('m/d/Y', strtotime($service_details->service_datetime)); ?>" data-bv-field="date"/>

                            </div></div>
                            
                             <div class="col-md-4" style="display:none">
                            <div class="form-group">
                            <?php // print_r($service_details);
							//echo $service_details->service_datetime;
							
							?>
                                <label>Return Date *</label>
                               
                            
                                    <input id="service_return_date" name="service_return_date" type='text' class="form-control date-picker" 
                                    value="<?php if(!$service_id){echo date('m/d/Y');} else echo date('m/d/Y', strtotime($service_details->service_return_date)); ?>" data-bv-field="date"/>

                            </div></div>
                             <div class="col-md-3" id="supp_wap">
                            <div class="form-group">
                           
                           
															<label>Supplier  * </label><?php //print_r($suppliers);?>
                                                          <select id="supp_id" class="form-control" name="supp_id">
                                                                  <option value="">-- Select --</option>
																  <?php 
															
															foreach ($suppliers as $row)
															{
																$sel='';
																if($service_details->supp_id==$row['supp_id']){
																$sel='selected';
																}
															?> 
																							   <option <?php echo $sel; ?>  value="<?php echo $row['supp_id'];?>"><?php echo $row['supp_company_name']; ?></option>
															 <?php }  ?>
																		
																	</select>
                                                             
														</div></div>
                                                        
                                        
                                         
                                        <div class="col-md-3 pull-left" id="warranty_wap" >
                            <div class="form-group">
															<label>Warranty  * </label><?php //print_r($suppliers);?>
                                                          <select id="service_warranty_available" class="form-control" name="service_warranty_available">
                                                                  <option value="">-- Select --</option>
<option value="1" <?php if(isset($service_details->service_warranty_available)&& $service_details->service_warranty_available==1){echo 'selected';}  ?>>Avalable</option>
<option value="0" <?php if(isset($service_details->service_warranty_available)&& $service_details->service_warranty_available==0){echo 'selected';}  ?>>Not Avalable</option>
																		
																	</select>
                                                             
														</div></div>   
                                                        
                                                        
   <div class="col-sm-12"></div>                                                          
  
  <div style="clear:both;"></div>
   <div class="panel-heading" style="font-weight: 700;">Fault Details</div>
  
  <!-- ..................-->
  
  
  <div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->no_power)&& $service_details->no_power=='No Power'){echo 'checked';} ?> type="checkbox" class="radio" value="No Power" name="no_power" />No Power
</label>

</div> 


<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->auto_switch_off)&& $service_details->auto_switch_off=='Auto Switch off'){echo 'checked';} ?> type="checkbox" class="radio" value="Auto Switch off" name="auto_switch_off" />Auto Switch off
</label>

</div> 

<div class="col-xs-3">
<label>
    <input <?php if(isset($service_details->drop)&& $service_details->display=='Drop Damage N/P'){echo 'checked';} ?> type="checkbox" class="radio" value="Drop Damage N/P" name="drop" />Drop Damage N/P
</label>
</div>

<!--<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->drop)&& $service_details->drop=='Drop Damage N/P'){echo 'checked';} ?> type="checkbox" class="checkbox" value="Drop Damage N/P" name="drop" />Drop Damage N/P
</label>

</div> -->

<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->water_damage)&& $service_details->water_damage=='Water Damage N/P'){echo 'checked';} ?> type="checkbox" class="radio" value="Water Damage N/P" name="water_damage" />Water Damage N/P
</label>

</div>

<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->speaker)&& $service_details->speaker=='Speaker'){echo 'checked';} ?> type="checkbox" class="radio" value="Speaker" name="speaker" />Speaker
</label>

</div> 

<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->short)&& $service_details->short=='Phone Short'){echo 'checked';} ?> type="checkbox" class="radio" value="Phone Short" name="short" />Phone Short
</label>

</div>  

<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->no_service)&& $service_details->no_service=='No Service'){echo 'checked';} ?> type="checkbox" class="radio" value="No Service" name="no_service" />No Service
</label>

</div> 

<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->mic)&& $service_details->mic=='Mic'){echo 'checked';} ?> type="checkbox" class="radio" value="Mic" name="mic" />Mic
</label>

</div> 

<div class="col-xs-3">
<label>
    <input <?php if(isset($service_details->display)&& $service_details->display=='Display'){echo 'checked';} ?> type="checkbox" class="radio" value="Display" name="display" />Display
</label>
</div> 

<!--<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->display)&& $service_details->display=='Display'){echo 'checked';} ?> type="checkbox" class="checkbox" value="Display" name="display" />Display</label>

</div> -->

<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->service_drop)&& $service_details->service_drop=='Service Drop'){echo 'checked';} ?> type="checkbox" class="radio" value="Service Drop" name="service_drop" />Service Drop
</label>

</div> 

<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->ringer)&& $service_details->ringer=='Ringer'){echo 'checked';} ?> type="checkbox" class="radio" value="Ringer" name="ringer" />Ringer
</label>

</div> 

<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->charging)&& $service_details->charging=='Charging'){echo 'checked';} ?> type="checkbox" class="radio" value="Charging" name="charging" />Charging
</label>

</div> 

<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->phone_struck)&& $service_details->phone_struck=='Phone Struck'){echo 'checked';} ?> type="checkbox" class="radio" value="Phone Struck" name="phone_struck" />Phone Struck
</label>

</div> 

<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->lock)&& $service_details->lock=='Lock /Software'){echo 'checked';} ?> type="checkbox" class="radio" value="Lock /Software" name="lock" />Lock /Software
</label>

</div> 

<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->other)&& $service_details->other=='Other'){echo 'checked';} ?> type="checkbox" class="radio" value="Other" name="other" />Other
</label>

</div> 

 <div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->service_marks)&& $service_details->service_marks=='Marks on cover / desplay'){echo 'checked';} ?> type="checkbox" class="radio" value="Marks on cover / desplay" name="service_marks" />Marks on cover / desplay</label>
</div> 


<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->service_burn)&& $service_details->service_burn=='Burn Marks'){echo 'checked';} ?> type="checkbox" class="radio" value="Burn Marks" name="service_burn" />Burn Marks</label>
</div> 

<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->service_physical)&& $service_details->service_physical=='Physical Damage'){echo 'checked';} ?> type="checkbox" class="radio" value="Physical Damage" name="service_physical" />Physical Damage</label>
</div> 

<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->service_tempered)&& $service_details->service_tempered=='Tempered'){echo 'checked';} ?> type="checkbox" class="radio" value="Tempered" name="service_tempered" />Tempered</label>
</div> 
<div class="col-xs-3">

<label>
    <input <?php if(isset($service_details->service_scratch)&& $service_details->service_scratch=='Scratch Marks'){echo 'checked';} ?> type="checkbox" class="radio" value="Scratch Marks" name="service_scratch" />Scratch Marks</label>
</div>
  
  <!--..............-->

 <div class="col-sm-12"></div> 

  
  
  <!--Start Accessories Attached-->
<div class="">
 <div style="clear:both"></div> 
<div class="panel-heading" style="font-weight: 700;">Accessories Attached</div>
 <div class="col-sm-12">
 
 	<div class="">
 	<!--<div class="col-sm-12 accessories_header"><div>Accessories Attached</div></div>-->
     
   </div>
 	<div class="col-xs-2">
    <input <?php if(isset($service_details->aa_battery)&& $service_details->aa_battery=='Battery'){echo 'checked';} ?> type="checkbox" class="checkbox" value="Battery" name="aa_battery" />Battery</label>
    </div>
    
    <div class="col-xs-2">
    <input <?php if(isset($service_details->aa_charger)&& $service_details->aa_charger=='Charger'){echo 'checked';} ?> type="checkbox" class="checkbox" value="Charger" name="aa_charger" />Charger</label>
    </div>
    
    <div class="col-xs-2">
    <input <?php if(isset($service_details->aa_back_cover)&& $service_details->aa_back_cover=='Back Cover'){echo 'checked';} ?> type="checkbox" class="checkbox" value="Back Cover" name="aa_back_cover" />Back Cover</label>
    </div>
    
    <div class="col-xs-2">
    <input  <?php if(isset($service_details->aa_mem_card)&& $service_details->aa_mem_card=='Mem Card'){echo 'checked';} ?> type="checkbox" class="radio" value="Mem Card" name="aa_mem_card" />Mem Card</label>
    </div>
    
    <div class="col-xs-2">
    <input <?php if(isset($service_details->aa_others)&& $service_details->aa_others=='Others'){echo 'checked';} ?> type="checkbox" class="radio" value="Others" name="aa_others" />
    Full Box</label>
    </div>
    
    <div class="col-sm-12">
    <div>&nbsp;</div>
    Remarks .................................
    </div>
 
 </div>

</div>
<!--End Accessories Attached-->
                                                      
							
   <div id="invoice_details_wap" style="display:none">
  <div class="col-sm-12" style="margin-bottom:10px">	

<hr/>    
<h4>Invoice Details</h4>
		                               
	</div>  
    
     <div class="col-sm-4">
<div class="form-group">

<label>
Invoice No.
</label>
<br/>
<div id="sale_reference_no_txt"></div>
</div>
</div>

     <div class="col-sm-4">
<div class="form-group">

<label>
Outstanding
</label>
<br/>
<div id="outstanding_txt">0.00</div>
</div>
</div>

  <div class="col-sm-4">
<div class="form-group">

<label>
Invoice Date
</label>
<br/>
<div id="sale_datetime_txt">0.00</div>
</div>
</div>

  <div class="col-sm-3">
<div class="form-group">

<label>
Warranty Period
</label>
<br/>
<div id="warranty_months_txt" style="float:left">0</div> Month(s)
</div>
</div>

 
    <div class="col-sm-4">
  <div class="form-group">    
                                                                                                
<div id="invoice_details"></div>
                                            
	</div>
</div> 
</div> <!-- /invoice_details_wap-->


<!--GRN Details start-->
<div id="grn_details_wap" style="display:none;">
    <div class="col-sm-12" style="margin-bottom:10px">	
    <hr/>
        <h4>GRN Details</h4>
                                       
    </div>
    <div class="col-sm-4">
    <div class="form-group">
    <label>GRN No.</label>
    <br/>
    <div id="grn_reference_no_txt"></div>
    </div>
    </div>
    <div class="col-sm-4">
    <div class="form-group">
    <label>GRN Date</label>
    <br/>
    <div id="grn_date_txt"></div>
    </div>
    </div>
</div> <!--/grn_details_wap-->
<!--GRN Details end-->   
    
<div style="clear:both"></div> 
    <div class="panel-heading" style="font-weight: 700;">Service Details</div> 
  <div class="col-sm-12" style="margin-bottom:10px">	<br>
	
    
   
	                               
	</div>

 
<div class="col-sm-4">
<div class="form-group">
<label>
Item Fault
</label>
<br/>
<textarea class="form-control" cols="10" rows="2" name="nature_of_work" ><?php if(isset($service_details->nature_of_work)){echo $service_details->nature_of_work;}  ?></textarea>
</div>
</div>

<div class="col-sm-4">
<div class="form-group">
<label>
Remarks
</label>
<br/>
<textarea class="form-control" cols="10" rows="2" name="service_remark" ><?php if(isset($service_details->service_remark)){echo $service_details->service_remark;}  ?></textarea>
</div>
</div>  

<div class="col-sm-4" style="display:none">
<div class="form-group">

<label>
Responsible Person 
</label>
<br/>
<input type="text" id="service_responsible_person" name="service_responsible_person" class="form-control"data-bv-field="date" value="<?php if(isset($service_details->service_responsible_person)){echo $service_details->service_responsible_person;}  ?>">
</div>
</div>

<div class="col-sm-4">
<div class="form-group">

<label>
Service Charge
</label>
<br/>
<input type="text" id="service_charge" name="service_charge" class="form-control"data-bv-field="date" value="<?php if(isset($service_details->service_charge)){echo $service_details->service_charge;}  ?>" readonly>
</div>
</div>
                                                                              
                                          
													</div>
												</div>
                                                
                                                  
											</div>
                                            
                                            
                                            
                                            
                                            
                                      
                                            
                                            
                                            
                                            
                                            
										</div> <!--col-md-8-->
 
 
 

                                         
 <div class="col-sm-12">
  <div class="form-group">
 
  
 </div>
 </div>
                                        
                                        <!-- item add box-->
                                        <div id="sticker" class="col-md-12">
											
                                        <!-- end item add box-->

									
                                                
                                              
                                                    
                                                    
                                                    
                                         
                                        
                                       			
										
													
                                        
                        </div> <!-- end: col-md-12-->
                        
                        
                        
                    
						
                        
                       
                      
                        
                        <div class="col-md-12">
                        <div class="modal-footer" style="margin-bottom:10px;">
            				<input type="submit" class="btn btn-primary" value="Submit" name="add_quotation" id="add_quotation"> <button id="reset" class="btn btn-danger" type="button">Reset</button>
            			</div>
                        </div>
                         <input name="qts_inv_discount_amount" type="hidden" id="sale_inv_discount_amount" value="0">
                        <input name="qts_total" type="hidden" id="sale_total" value="0">
                        <input name="qts_paid" type="hidden" id="sale_paid" value="0">
                        <input name="qts_balance" type="hidden" id="sale_balance" value="0">
                        <input name="rowCount" type="hidden" id="rowCount" value="<?php echo count($serviceitm_list);?>">
                        <input name="service_id" type="hidden" id="service_id" value="<?php echo $service_id;?>">
                         <input name="service_reference_no" type="hidden" id="service_reference_no" value="<?php if (isset($service_details->service_reference_no)) echo $service_details->service_reference_no; ?>">
                        
        <!--<input name="warehouse_id" type="hidden" id="warehouse_id" value="<?php echo $this->session->userdata('ss_warehouse_id');?>">   -->             
                        
          <!-- <input name="product_id" type="hidden" id="product_id" value="<?php if(isset($service_details->product_id)) echo $service_details->product_id;?>"> -->           
                        
                   		 </form>
									
							<!-- end: DYNAMIC TABLE PANEL -->
                            
                            
                           
                            
						</div>
					</div>

					
                    <!-- end grid -->
                    
					
			</div>
			<!-- end: PAGE -->
		</div>
		<!-- end: MAIN CONTAINER -->
		<!-- start: FOOTER -->
		<div class="footer clearfix">
			<div class="footer-inner">
				<?php date("Y");?> Developed by: Sallelanka Solutions (pvt) Ltd.
			</div>
			<div class="footer-items">
				<span class="go-top"><i class="clip-chevron-up"></i></span>
			</div>
		</div>
		<!-- end: FOOTER -->
		<!-- start: RIGHT SIDEBAR -->
		<!-- end: RIGHT SIDEBAR -->
		<div id="event-management" class="modal fade" tabindex="-1" data-width="760" style="display: none;">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							&times;
						</button>
						<h4 class="modal-title">Event Management</h4>
					</div>
					<div class="modal-body"></div>
					<div class="modal-footer">
						<button type="button" data-dismiss="modal" class="btn btn-light-grey">
							Close
						</button>
						<button type="button" class="btn btn-danger remove-event no-display">
							<i class='fa fa-trash-o'></i> Delete Event
						</button>
						<button type='submit' class='btn btn-success save-event'>
							<i class='fa fa-check'></i> Save
						</button>
					</div>
				</div>
			</div>
		</div>


<input name="tmpVal" type="hidden" id="tmpVal" value="0">


		<!-- start ajax model -->
		<div id="ajax-modal" class="modal fade" data-backdrop="static" data-keyboard="false" tabindex="-1" style="display: none;"></div>
		<!-- end ajax model -->
                
               					
 
                                    
		<!-- end: RIGHT SIDEBAR -->
		<!-- start: MAIN JAVASCRIPTS -->
<?php $this->load->view("common/footer"); ?>
<script src="<?php echo asset_url(); ?>js/jquery-ui.js" ></script>
<script src="<?php echo asset_url(); ?>js/moment-with-locales.js"></script> 
<script type="text/javascript" src="<?php echo asset_url(); ?>js/bootstrap-datetimepicker.js"></script> 
<script type="text/javascript" src="<?php echo asset_url(); ?>js/bootbox.min.js"></script> 
<script type="text/javascript" src="<?php echo asset_url(); ?>js/accounting.js"></script> 
<script type="text/javascript" src="<?php echo asset_url(); ?>js/accounting.min.js"></script> 

<!-- end: MAIN JAVASCRIPTS --> 

 		<!-- start: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY VALIDATION-->
		<script src="<?php echo asset_url(); ?>js/form-validation-create_service.js"></script>
        <script src="<?php echo asset_url(); ?>js/service.js"></script>
        <script src="<?php echo asset_url(); ?>js/sales.js"></script>
		<!-- end: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY  VALIDATION-->
        
		<!-- start: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY -->
    <!--    <script src="<?php echo asset_url(); ?>js/form-validation-loan_add.js"></script> 
<script src="<?php echo asset_url(); ?>js/loan_add.js"></script> 
<script src="<?php echo asset_url(); ?>js/loan_extra_itm_add.js"></script> -->


		<script src="<?php echo asset_url(); ?>/plugins/jquery-inputlimiter/jquery.inputlimiter.1.3.1.min.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/autosize/jquery.autosize.min.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/select2/select2.min.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/jquery.maskedinput/src/jquery.maskedinput.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/jquery-maskmoney/jquery.maskMoney.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/bootstrap-timepicker/js/bootstrap-timepicker.min.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/bootstrap-daterangepicker/moment.min.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/bootstrap-daterangepicker/daterangepicker.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/bootstrap-colorpicker/js/bootstrap-colorpicker.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/bootstrap-colorpicker/js/commits.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/jQuery-Tags-Input/jquery.tagsinput.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/bootstrap-fileupload/bootstrap-fileupload.min.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/summernote/build/summernote.min.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/ckeditor/ckeditor.js"></script>
		<script src="<?php echo asset_url(); ?>/plugins/ckeditor/adapters/jquery.js"></script>
		<script src="<?php echo asset_url(); ?>/js/form-elements.js"></script>
		<!-- end: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY -->
		<script>
		
		
//$('#search_by_invoice_details').hide();	


// searchable dropdown get data with ajax
$(".js-data-customer_id-ajax").select2({
ajax: {
url: "<?php echo base_url('customers/getCustomer') ?>",
		dataType: 'json',
		delay: 250,
		data: function (query) {
		if (!query)
				query = '';
		return {
		search_string: query,
				format: 'json'
		};
		},
		results: function (data) {
		return {
		results: $.map(data, function (item) {
		return {
		text: item.cus_name+ ' / '+ item.cus_phone,
				slug: item.cus_name+ '/'+ item.cus_phone,
				id: item.cus_id
		};
		
		})
		
		};
		},
		cache: true
}

});


    

function show_waking_cus_details(cus_id){
	//alert(cus_id);
	if(cus_id==1){
		//$('#service_walking_cus_name_wap').show();	
		//$('#service_walking_cus_phone_wap').show();	
	}else {
		$('#service_walking_cus_name_wap').hide();	
		$('#service_walking_cus_phone_wap').hide();	
	}
}

jQuery(window).load(function () {
	
<?php
  if (!empty($service_details->product_sn)){?>
  $('#service_item_avalable option:not(:selected)').prop('disabled', true);
   $('#service_type option:not(:selected)').prop('disabled', true);
	 //alert('<?php echo $service_details->product_sn;?>');		
  $('.js-data-product-sn-ajax').select2('data', {id: '<?php echo $service_details->product_sn;?>', text: '<?php echo $service_details->product_sn;?>'});
  
  //alert(2);
 // check_product_details();
 <?php } ?>
 
	
	 $(".js-data-product-sn-ajax").select2({
        ajax: {
			'type': 'POST',
				'url': '<?php echo base_url('service/get_product_sn?srh_warehouse_id=');?>'+$("#warehouse_id").val(),
							'data': {
							   srh_warehouse_id: 1,
							},
                dataType: 'json',
                delay: 0,
			
                data: function (query) {
							//alert(1);
                if (!query)
                        query = '';
                return {
                search_string: query,
				service_item_avalable: $("#service_item_avalable").val(),
                        format: 'json'
                };
                },
                results: function (data) {
                return {
                results: $.map(data, function (item) {
                return {
					//alert();
                text: item.pis_number+' ('+item.product_name+')',
                        slug: item.pis_number,
                        id: item.pis_number
                };
                })
                };
                },
                cache: true
         }
        });
		
	
	//$("#service_customer_id").select2();
	
	var service_type=$('#service_type').val();
	if(service_type=='Repair'){
		set_form_repair();
	}
	if(service_type=='Serial'){
		set_form_serial();
	}
	if(service_type=='Invoice'){
		set_form_invoice();
	}
	
	if($("#service_customer_id").val()==1){
		//$('#service_walking_cus_name_wap').show();	
		//$('#service_walking_cus_phone_wap').show();	
	}else {
		$('#service_walking_cus_name_wap').hide();	
		$('#service_walking_cus_phone_wap').hide();	
	}
	
//alert("sn:<?php //echo $service_details->product_sn ?>");	
	 
	
	 
	
 
 
});

function set_form_invoice(){
	$('#repair_hide').show();	
	$('#search_by_invoice_details').show();	
	$('#search_by_sn_details').hide();	
	$('#rep_item_sn').hide();	
	$('#rep_item_name').hide();	
	$('#supp_wap').show();	
	$('#warranty_wap').show();	
	$('#sn_item_name').show();	
}

function set_form_serial(){
	$('#repair_hide').show();
	$('#search_by_invoice_details').hide();	
	$('#search_by_sn_details').show();
	$('#rep_item_sn').hide();	
	$('#rep_item_name').hide();	
	$('#supp_wap').show();	
	$('#warranty_wap').show();	
	$('#sn_item_name').show();	
	$('#grn_details_wap').show();	
	$('#invoice_details_wap').show();
	
}
	

function set_form_repair(){
	$('#search_by_invoice_details').hide();	
	$('#search_by_sn_details').hide();
	$('#repair_hide').hide();
	$('#sn_item_name').hide();	
	$('#supp_wap').hide();	
	$('#warranty_wap').show();	
	$('#rep_item_sn').show();	
	$('#rep_item_name').show();		
}

	
$('select#service_type').on('change', function(){
	var v = $(this).val();
	//alert();
	 if ($(this).val() == 'Serial') {
		 set_form_serial();
			
            // append goes here
        }
		if ($(this).val() == 'Invoice') {
			set_form_invoice();
            // append goes here
        }
		if ($(this).val() == 'Repair') {
			set_form_repair();
			
            // append goes here
        }
});
		
$('input:radio[name="service_type"]').change(
    function(){
		
        if ($(this).is(':checked') && $(this).val() == 'Serial') {
			$('#search_by_invoice_details').hide();	
			$('#search_by_sn_details').show();	
			
            // append goes here
        }
		
		if ($(this).is(':checked') && $(this).val() == 'Invoice') {
			$('#search_by_invoice_details').show();	
			$('#search_by_sn_details').hide();	
            // append goes here
        }
    });		
		


			$('select#sale_id').on('change', function(){

			   		var v = $(this).val();

					$.ajax({
					  type: "get",
					  async: false,
					  url: "<?php echo base_url('sales/get_invoice_items'); ?>",
					  data: { sale_id: v },
					  dataType: "html",
					  success: function(data) {
						if(data != "") {
							$('#product_data').empty();
							$('#product_data').html(data);
							$("#product_id").select2({allowClear: true});
						} else {
							$('#product_data').empty();
							var default_data = '<select name="subcategory" id="subcategory" class="form-control search-select" data-placeholder="Select Category to load Subcategories"></select>';
							$('#product_data').html(default_data);
							$("#product_id").select2({allowClear: true});
							set_message("Product Info","No Subcategory found for the select category.");
						}},
					  error: function(){
       					alert('Error occured while getting data from server.');
    				  }
					  
					});
			});
					
		
	function check_product_details(){
		var product_sn=$('#product_sn').val();
		var service_type=$('#service_type').val();//$('input[name=service_type]:checked').val();
		var sale_id=$('#sale_id').val();
		var product_id=$('#product_id').val();
		
		$('#lording-gif').show();
		//alert(service_type);
		//get prodcut_id, customer , supplier, waranti avalable by sn
		if(!product_sn) product_sn='';
		
		{
		var url="<?php echo base_url();?>service/check_serial_no_details?sn="+product_sn+"&service_type="+service_type+"&sale_id="+sale_id+"&product_id="+product_id;
			$.post(url)
		  .done(function( data ) {
			  
			  var obj = jQuery.parseJSON(data);
			// alert(obj.cus_id);
			  $('#product_id').val(obj.product_id);
			  
			  $('#service_customer_id').val(obj.cus_id);
			  
			  $('#sale_reference_no_txt').text(obj.sale_reference_no);
			  $('#outstanding_txt').text(obj.outstanding);
			  $('#warranty_months_txt').text(obj.warranty_months);
			  $('#sale_datetime_txt').text(obj.sale_datetime);
			  $('#supp_id').val(obj.supp_id);
			  
			  $('#grn_reference_no_txt').text(obj.grn_id);
			  $('#grn_date_txt').text(obj.grn_date);
			  
			   $('#service_warranty_available').val(obj.warranty_avalable);
			   if(obj.warranty_avalable!=1){
			   $('#service_warranty_available').css('border-color', 'red');  
			   }else{
				    $('#service_warranty_available').css('border-color', '#ccc');  
			   }
			   
			   if(obj.outstanding){
				    $('#outstanding_txt').css('color', 'red'); 
					
					$("#add_quotation").prop("disabled", true);
			   }else {
				    $('#outstanding_txt').css('color', '#000000');
					$("#add_quotation").prop("disabled", false);
			   }
			   
			   
			   var item_details='';
			item_details="<table class=\"table_custom\">";
			var product_full_name=obj.product_name;
			item_details=item_details+"<tr><td>Name</td><td width='5%'>:</td><td>"+product_full_name+"</td></tr>";
			item_details=item_details+"<tr><td>GRN</td><td>:</td><td>"+obj.grn_no+"</td></tr>";
			//item_details=item_details+"<tr><td>Supplier </td><td>:</td><td>"+obj.supp_name+"</td></tr>";
			
			item_details+="</table>";
			$("#item_details").html(item_details);
			   
			   $('#lording-gif').hide();
			 //$("div.id_100 select").val("val2");
			  //alert(obj.cus_id);
			  
			  //if(!obj.status){
			 // var fld='#sn_item_'+id;
			 // $(fld).val('');
			 // alert('Invalid Serial No.:'+sn);
			 // }
		  });
		}
		
	}
	
		
			jQuery(document).ready(function() {
				
				
				
				//$("#service_customer_id").select2();
				//$("#product_sn").select2();
				//$("#sale_id").select2();
				
				calculateTotal();
				
				function deleteRequisitionItem(val){
				alert();	
				}
				//Main.init();
				FormElements.init();
				//$('#loan_date').val('29-07-2016')
				



    
		
			});
			
function changeQtyByProductID(qty,nxtCount){
	//alert(qty+' '+nxtCount);
	
	if(isNaN(qty)) {
		displayNotice('page','Invalid Quantity');
		var quantity_fld='#serviceitm_qty'+nxtCount;
		var product_id_fld='#product_id'+nxtCount;
		
		//alert(quantity_fld);
		var oldVal=$('#tmpVal').val();
		$(quantity_fld).val(oldVal); //set last val
	}else {
		//getavalable product count
		var product_id_fld='#product_id'+nxtCount;
		var product_id=$(product_id_fld).val();
		
		var warehouse_id=$('#warehouse_id').val();

		//end getavalable product count
		calculateTotal();
		//displayNotice('page','Product quantity successfully updated!');
	}
}

function getNextRefNo(){
	//return 'SALE/2015/11/0001';
	//alert();
	
	$.post( "<?php echo base_url();?>service/get_next_ref_no")
	  .done(function( data ) {
		  var obj = jQuery.parseJSON(data);
		  $('#qts_reference_no').val(obj.qts_reference_no);
	  });
	//return false;
}

function insertPurchases_OrderData(){
	
	var error=false;
	var service_type=$('#service_type').val();
	
	if(service_type==''){
		 error=true;
		 $('#service_type').css('border-color', '#C80000');    
	}
	
	
	if(service_type=='Serial'){
		if($('#product_sn').val()==''){
			 error=true;
			 $('#product_sn').css('border-color', '#C80000');    
		}
		if($('#product_id').val()==''){
			 //error=true;
			 $('#product_id').css('border-color', '#C80000');    
		}
		if($('#service_customer_id').val()==''){
			 error=true;
			 $('#service_customer_id').css('border-color', '#C80000');    
		}
		if($('#supp_id').val()==''){
			 error=true;
			 $('#supp_id').css('border-color', '#C80000');    
		}
		if($('#service_warranty_available').val()==''){
			 error=true;
			 $('#service_warranty_available').css('border-color', '#C80000');    
		}
	}
	
	if(service_type=='Invoice'){
		if($('#sale_sn').val()==''){
			 error=true;
			 $('#sale_sn').css('border-color', '#C80000');    
		}
		if($('#product_id').val()==''){
			 error=true;
			 $('#product_id').css('border-color', '#C80000');    
		}
		if($('#service_customer_id').val()==''){
			 error=true;
			 $('#service_customer_id').css('border-color', '#C80000');    
		}
		if($('#supp_id').val()==''){
			 error=true;
			 $('#supp_id').css('border-color', '#C80000');    
		}
		if($('#service_warranty_available').val()==''){
			 error=true;
			 $('#service_warranty_available').css('border-color', '#C80000');    
		}
	}

	if(service_type=='Repair'){
		if($('#service_rep_item_sn').val()==''){
			 error=true;
			 $('#service_rep_item_sn').css('border-color', '#C80000');    
		}
		if($('#service_rep_item_name').val()==''){
			 error=true;
			 $('#service_rep_item_name').css('border-color', '#C80000');    
		}
		if($('#service_customer_id').val()==''){
			 error=true;
			 $('#service_customer_id').css('border-color', '#C80000');    
		}
		
	}	
	if(error){
		alert('Plese enter required details');
		return false;
	}
	
	//alert();
	
	
	
	var type='A';
	var qts_reference_no=$('#qts_reference_no').val();
	 var fields = $("#create_service_form").serialize();
	  
	  var rowCount=$('#rowCount').val();

	  {
		 // $("#add_quotation").prop("disabled", true);
		//  $("#add_quotation").val('Please wait...');

		 // create_service_form.add_quotation.disabled = true;
   		// create_service_form.add_quotation.value = "Please wait...";
    	//	return true;
	
	//alert(fields);
	//type:type, qts_reference_no:qts_reference_no
	$.post( "<?php echo base_url();?>service/save_service", fields)
	  .done(function( data ) {
		  var obj = jQuery.parseJSON(data);
			if(obj.error==1){
				
				$('.alert-success').hide();
				$('.alert-danger').show();
				$( ".errortxt" ).text( obj.disMsg );
				window.scrollTo(500, 0);
				//empty item table
				
			}
			if(obj.error==0){
				//$('.alert-danger').hide();
				//$('.alert-success').show();
				//$( ".succetxt" ).text( obj.disMsg );
				window.scrollTo(500, 0);
				//$("#soTable tr:gt(0)").remove();
				$("#soTable > tbody").empty();
				displayNotice('page','Service successfully added!');
				
				clearForm();
				//empty footer details
				
				//alert(obj.qts_id);
				sendUrl='service/details/'+obj.service_id;
				//alert(sendUrl);
				
				window.location.href = "<?php echo base_url();?>"+sendUrl;
				
			}
			
			
	  });
return false;

	  }
	  
}



 

//function to initiate bootstrap-datepicker
$(function () {
	//showKeys();
	
	var curserviceDate = new Date();
	
	
	$('#pouired_date_1_del').datetimepicker({
		defaultDate: new Date()
		});
	
	//$("#warehouse_id").select2();
	//$("#supp_id").select2();
	//$("#customer_id").select2();
	
});	


<!--start add service item-->
function add_items(){

        //ItemnTotals();

        $("#add_item").autocomplete(

		{

            source: '<?php echo base_url();?>sales/suggestions?t='+$("#in_type").val()+'&cus_type='+ $('#cus_type').val()+'&city_id='+ $('#city_id').val(),

            minLength: 1,

            autoFocus: false,

            delay: 5,

            response: function (event, ui) {

			

				if (ui.content.length == 1 && ui.content[0].product_id != 0)

				{

					ui.item = ui.content[0];

 					$(this).data('ui-autocomplete')._trigger('select', 'autocompleteselect', ui);

					$(this).autocomplete('close');

                    $(this).removeClass('ui-autocomplete-loading');

				}else if(ui.content.length ==0){

					var noResult = { value:"",label:"No matching result found! Product might be out of stock in the selected warehouse." };

            		ui.content.push(noResult);

				}else {



				}

			

            },

            select: function (event, data) {

				//alert( "You selected: " + data.item.product_id );

				if(data.item.value){

					

					//check is added prodcut

					rowCount=parseInt($('#rowCount').val());

					var tmp='';

					if(rowCount){

	  					tmp=isAddedProduct(data.item.product_id);

						

						

					}

	   				if(!tmp)

					{
						/*
						alert('item_cost:'+data.item.item_cost);
						alert('product_price:'+data.item.product_price);
						if(data.item.item_cost>data.item.product_price){
							alert('Product cost greater than selling price');	
							
						}
						*/

				addProductToListByID(data.item.product_id,data.item.product_name,data.item.product_code,data.item.product_price,data.item.product_part_no,data.item.product_oem_part_number,data.item.item_cost,data.item.product_sn,data.item.product_w,data.item.product_sn_exissts);

				

				

						//alert(data.item.product_sn);

						//add next serial no.

						var rowCount=parseInt($('#rowCount').val());

						var product_sn_fld='#product_sn_'+rowCount;

						var product_sn_val=($(product_sn_fld).val());

						if(data.item.is_search_by_sn){

							if(product_sn_val) {

								$(product_sn_fld).val(product_sn_val+','+data.item.product_sn);

							}else{

								$(product_sn_fld).val(data.item.product_sn);

							}
							
							//set sn cost start
						
							
								var prouct_price=data.item.product_price;
							
								//alert(prouct_price);
								
								if(data.item.pis_cost_price){
								if (data.item.pis_cost_price>prouct_price) 
								{
									displayNotice('Error','Product cost greater than selling price');
									//bootbox.alert("Product cost greater than selling price");	
										
								}else{
									
								}
								
								
									//set serial no item cost
									var fld_item_cost="#item_cost_"+rowCount;
									//alert(data.item.pis_cost_price);
									
									if(data.item.pis_cost_price!='0.00'){
										$(fld_item_cost).val(data.item.pis_cost_price);
									}	
								
								
								
								}
							
						
							//end set cost

						}

				

				

				

					}else {

						//alert(data.item.product_sn);

						//add next serial no.

						var rowCount=parseInt($('#rowCount').val());

						var product_sn_fld='#product_sn_'+rowCount;

						var product_sn_val=($(product_sn_fld).val());

						if(data.item.is_search_by_sn){

							if(product_sn_val) {

								$(product_sn_fld).val(product_sn_val+','+data.item.product_sn);

								}else{

								$(product_sn_fld).val(data.item.product_sn);

							}

						}

						

						calculateTotal();

					}

				

				

				$("#add_item").val('');

					 return false;

				}

				$(this).autocomplete('close');

                    $(this).removeClass('ui-autocomplete-loading');

				

            }

        });

}
		</script>
        
            <script>

<?php if (isset($service_details->service_customer_id) && $service_details->service_customer_id != 0) { ?>
       
     
		
		 $('.js-data-customer_id-ajax').select2('data', {id: '<?php echo $service_details->service_customer_id;?>', text: '<?php echo $service_details->cus_name;?> / <?php echo $service_details->cus_phone;?>'});
      
    <?php } ?>
	    </script>
<!--end service item-->

</body>
	<!-- end: BODY -->
</html>