<?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;

$acctrnss_id=0;
                        $ref_id = new Common_Model();
                         $whe_details=$ref_id->get_warehouse_info($this->session->userdata('ss_warehouse_id'));
                        
						$ss_user_id=$this->session->userdata('ss_user_id');
						$shift_date=date("Y-m-d");
						if($whe_details['shift_enable']){
						$active_shift_des=$ref_id->get_active_shift_by_user_id_date($ss_user_id,$shift_date);
					//	print_r($active_shift_des);
						$acctrnss_id=$active_shift_des['acctrnss_id'];
						}
?>



<?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/details/$service_id"); ?>">
										Service Details
									</a>
								</li>

								<li class="active">
										Service Item Add
								</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> Service Item Add</h1>
							</div>

                            <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;Service Item Add
								</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> 
                            
                  
                  
   <div class="buttons">
<div class="btn-group btn-group-right" style="float:right;">

<!-- btn-group-justified-->
<!--<div class="btn-group"><a title="" class="tip btn btn-primary tip" data-target="#myModal" data-toggle="modal" href="#" data-original-title="Add Payment" id="modal_ajax_sales_payment_btn"><i class="fa fa-money"></i> <span class="hidden-sm hidden-xs">Add Payment</span></a></div>-->


<div class="btn col-xs-2"><a href="<?php echo base_url("service/details/$service_id"); ?>" title="" class="tip btn btn-primary" data-original-title="Print"><i class="clip-list"></i> <span class="hidden-sm hidden-xs">Service Details</span></a>
</div>
 
</div>
</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="col-sm-12" style="margin-bottom:10px">			
                                    
														</div> -->
                                                        
                                                                                                              
                                                        

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

<hr/>    
<h4>Invoice Details</h4>
		                               
	</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>
												</div>
                                                
                                                  
											</div>
                                            
                                            
                                            
                                            
                                            
<!--start service item-->
<div style="clear:both"></div> 
<!--    <div class="panel-heading" style="font-weight: 700;">Service Items</div> -->
    <div class="col-sm-12">
        <!-- auto complete start -->
        <div class="input-group wide-tip">
        	<div style="padding-left: 10px; padding-right: 10px;" class="input-group-addon">
        		<i class="fa fa-2x fa-barcode addIcon"></i>
        	</div>
        	<input type="text" placeholder="Please add products to order list" id="add_item" class="form-control input-lg" value="" name="add_item" onClick="add_items()" style="border-radius: 6px;font-size: 18px;height: 46px;line-height: 1.33;padding: 10px 16px;">
        </div>
        <!-- end auto complete end -->
        
        <!--start table-->
        <div class="clearfix"></div>

											<div class="control-group table-group" style="margin-top:5px">

												<label class="table-label">Service Items</label>

													<div class="controls table-controls">
<table class="table items table-striped table-bordered table-condensed table-hover" id="soTable">

															<thead>

																<tr>

																	<th class="col-md-4">Product Name (Product Code)</th>

																	<th class="">Warranty(Months)</th>

																	<th class="col-md-2">Selling Price</th>

																	<th class="">Quantity</th>

																	<th class="col-md-1 text-right">Discount </th>

																	

																	<th class="text-right">Subtotal<span class="currency"></span>

                                                                    </th>

																	<th style="width: 30px !important; text-align: center;"><i class="fa fa-trash-o"></i></th>

																</tr>

															</thead>

																	<tbody>

																		<tr data-item-id="144680019784" class="row_144680019784" id="row_1446800197032">

																			<td>

																				

																			</td>

																			<td class="text-right"></td>

																			<td class="text-right">

																				

																			</td>

																			<td>

																				

																			</td>

																			<td class="text-right">

																				

																			</td>

																			<td class="text-right">

																				

																			</td>

																			

																			<td class="text-center">

																			

																			</td>

																		</tr>
                                                                        
  <?php 
		//print_r($sale_item_list);
        $tmpcount=0;
		$Subtotal=0;
        foreach ($sale_item_list as $row)
        {
        $tmpcount++;
		$product_id=$row['product_id'];
		$Subtotal+=$row['gross_total'];
		
		//calculate qty: returnqty=soldqty-alredy returned qty
		$alredyReturnedQty=0;
		//$modelSR = new Sales_Return_Model();
		//$alredyReturnedQty = $modelSR->get_sales_return_product_qty($product_id,$sale_details['warehouse_id'],$sale_id);
		$remaintQty=$row['quantity']-$alredyReturnedQty;
        ?> 
                <tr id="row_<?php echo $tmpcount; ?>" class="child">
                <td>
				
				<?php echo $row['product_name']; ?> (<?php echo $row['product_code']; ?>)<?php if ($row['product_part_no']) echo ", Part No.:".$row['product_part_no']; ?>
<?php if ($row['product_oem_part_number']) echo ", OEM Part No.:".$row['product_oem_part_number']; ?>
<input type="hidden" id="product_id_<?php echo $tmpcount ?>" value="<?php echo $product_id ?>" name="row[<?php echo $tmpcount ?>][product_id][]" class="form-control text-center rquantity"></td>
<td>
<input name="row[<?php echo $tmpcount ?>][product_w][]" value="<?php echo $row['product_w'];?>" id="product_w_<?php echo $tmpcount ?>" type="text">
<input name="row[<?php echo $tmpcount ?>][is_added_item][]" value="1" id="is_added_item_<?php echo $tmpcount ?>" type="hidden">
</td>
                <td class="text-right">
                <input class="" name="row[<?php echo $tmpcount ?>][product_sn][]" value="" id="product_sn_<?php echo $tmpcount ?>" type="hidden">
                <input class="" name="row[<?php echo $tmpcount ?>][product_sn_exissts][]" readonly value="<?php echo $row['product_sn_exissts']; ?>" id="product_sn_exissts_<?php echo $tmpcount ?>" type="hidden">
                
                <input type="hidden" value="<?php echo $row['unit_price'] ?>" id="product_price_<?php echo $tmpcount ?>" name="row[<?php echo $tmpcount ?>][unit_price][]"><?php echo number_format($row['unit_price'], 2, '.', ',') ?>
                
                <input type="hidden" value="0" id="item_price_p_<?php echo $tmpcount ?>" name="row[<?php echo $tmpcount ?>][item_price_p][]" style="width:50px;">
                
                <input name="row[<?php echo $tmpcount ?>][item_cost][]" readonly="" id="item_cost_<?php echo $tmpcount ?>" value="<?php echo $row['item_cost'] ?>" type="hidden">
                </td>
                
                <td><?php //echo $alredyReturnedQty ?>
                <input type="text" onChange="changeQtyByProductID(this.value,<?php echo $tmpcount ?>);" onClick="this.select(); setTmpVal(this.value);" id="quantity_<?php echo $tmpcount ?>" value="<?php echo $remaintQty ?>" name="row[<?php echo $tmpcount ?>][qty][]" class="form-control text-center rquantity" style="width: 50px; margin-right: 5px; float: left;">
                
                <i style="cursor: pointer; margin-top: 3px;" id="addIcon" class="fa fa-2x fa-plus-circle addIcon" onClick="pop_up_add_serial_no('<?php echo $tmpcount;?>')" title="Add Serial No."></i>
                </td>
                
                <td class="text-right"><span id="sdiscount_1446800197032" class="text-right sdiscount text-danger">
                <input type="text" style="width:50px;" id="discount_<?php echo $tmpcount ?>" value="<?php echo $row['discount']; ?>" name="row[<?php echo $tmpcount ?>][discount][]" onChange="changeDiscountByProductID(this.value,1);">
                 </span>
                 <input type="hidden" id="discount_val_<?php echo $tmpcount ?>" value="<?php echo $row['discount_val']; ?>" name="row[<?php echo $tmpcount ?>][discount_val][]">
                 <input type="hidden" id="discount_val_tot_<?php echo $tmpcount ?>" value="0" name="row[<?php echo $tmpcount ?>][discount_val_tot][]"></td>
                
                <td class="text-right">
                <span id="subtotal_<?php echo $tmpcount ?>" class="text-right ssubtotal">
				
				<?php echo number_format($row['gross_total'], 2, '.', ',') ?></span>               
                <input type="hidden" id="gross_total_<?php echo $tmpcount ?>" value="<?php echo $row['gross_total'] ?>"
                 name="row[<?php echo $tmpcount ?>][gross_total][]">
                
                </td>
                <td><a onClick="deleteSalesItem(<?php echo $tmpcount ?>)"><i style="cursor:pointer;" title="Remove" id="1446800197032" class="fa fa-times tip podel"></i></a></td>
                </tr>
<?php }?>                                                                         
                                                                        
                                                                        

																	</tbody>
                                                                    
                                                                    
                                                                    

															<tfoot>

                                                                <tr class="tfoot active" id="tfoot">

																	<th colspan="5" class="text-right">Total Amount</th>

																	<th class="text-right"><span id="Subtotal"><?php if(!empty($sale_details['sale_total']))echo $sale_details['sale_total'];?></span></th>

																<th></th>	

																</tr>

															</tfoot>

														</table>
                                                        </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;}  ?>">
</div>
</div>  -->                                                  
                                                        
                                                        
                                                        
                                                        
        <!--end table-->
    </div>
    
</div>
<!--end service item-->                                         
                                            
                                            
                                            
                                            
                                            
										</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-->
                        
                        
                        
<input title="" data-original-title="" value="" class="form-control input-tip text-right" id="sale_inv_discount" name="sale_inv_discount" onchange="changeMainDiscount(this.value)" type="hidden">                    
						
                        
   <?php //print_r($service_details);?>                    
                      
                        
                        <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="warehouse_id" type="hidden" id="warehouse_id" value="<?php echo $service_details->warehouse_id;?>">
                          <input name="customer_id" type="hidden" id="customer_id" value="<?php echo $service_details->service_customer_id;?>">
                         <?php  //echo "sale_id:".$sale_id;?>
                          <input name="sale_id" type="hidden" id="sale_id" value="<?php echo $sale_id;?>">
                        <input name="sale_total" type="hidden" id="sale_total" value="<?php if(!empty($sale_details['sale_total']))echo $sale_details['sale_total'];?>">
                         
                        <input name="qts_paid" type="hidden" id="sale_paid" value="0">
                        <input name="sale_datetime" type="hidden" id="sale_datetime" value="<?php echo date("Y-m-d H:i:s");?>">
                        <input name="acctrnss_id" type="hidden" id="acctrnss_id" value="<?php echo $acctrnss_id;?>">
                        <input name="qts_balance" type="hidden" id="sale_balance" value="0">
                        <input name="rowCount" type="hidden" id="rowCount" value="<?php echo count($sale_item_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 -->
		


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

<a id="modal_ajax_serial_no" data-toggle="modal" href="#"></a> 
<a id="modal_ajax_serial_no_view" data-toggle="modal" href="#"></a>
<input name="" type="text" id="curr_row_no" 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(); ?>/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();	





	
		
			jQuery(document).ready(function() {
			    
			    $('#create_service_form').on('keyup keypress', function(e) {
                    var keyCode = e.keyCode || e.which;
                  if (keyCode === 13) { 
                    e.preventDefault();
                    return false;
                  }
                });
                				
				
				
				//$("#service_customer_id").select2();
				//$("#product_sn").select2();
				//$("#sale_id").select2();
				
				//calculateTotal();
				
				//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();
		
		//alert(qty+' '+nxtCount);
		
		//displayNotice('page','Product quantity successfully updated!');
	}
}



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();
	  
	  /*
	  sncount = 0;
	  $('table#soTable > tbody  > tr').each(function(index, tr) { 
			
			var row_id = tr.attributes['id'].value;
			var new_row_id = row_id.replace("row_", "");
			var pproduct_sn_exissts= $('#product_sn_exissts_'+new_row_id).val();
			var pproduct_sn= $('#product_sn_'+new_row_id).val();
			if(pproduct_sn_exissts==1){
				if(pproduct_sn=='')
					sncount++;
			}
			
		});

		if(sncount > 0){
			alert('select serials');
			sncount=0;
			return false;
		}
	  
	  */

	  {
		 $("#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_items", fields)
	  .done(function( data ) {
		  var obj = jQuery.parseJSON(data);
		  //alert(error);
			if(obj.error==1){
				
				$('.alert-success').hide();
				$('.alert-danger').show();
				$( ".errortxt" ).text( obj.disMsg );
				window.scrollTo(500, 0);
				//empty item table
				
			}
			if(!obj.error)
			{
				//$('.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.service_id);
				
				//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();
	
});	


function addextraprice(){

	calculateTotal();

}


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

        //ItemnTotals();
		var cat_id=4;
	var cat_id='';

        $("#add_item").autocomplete(

		{


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

            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');

				

            }

        });

}
/* end service item */

function pop_up_add_serial_no(row_no){

	$("#curr_row_no").val(row_no);

	//alert(1);

	document.getElementById("modal_ajax_serial_no").click();

	

}

$('a#modal_ajax_serial_no').on('click', function () {

	var curr_row_no=$("#curr_row_no").val();
	var warehouse_id=$("#warehouse_id").val();

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

	var qtyfld='#quantity_'+curr_row_no;

	var productfld='#product_id_'+curr_row_no;

	//alert(qtyfld);

	var qty=parseFloat($(qtyfld).val());

	var product_id=$(productfld).val();
	
	var gross_totalfld='#gross_total_'+curr_row_no;
	var gross_total=parseFloat($(gross_totalfld).val());
	var each_price=gross_total/qty;
	//alert(each_price);

	//alert(curr_row_no);

	// create the backdrop and wait for next modal to be triggered

	$('body').modalmanager('loading');

	setTimeout(function () {

		var url="<?php echo base_url("sales/add_serial_no/");?>/"+curr_row_no+'/'+qty+'/'+product_id+'/'+warehouse_id+'/'+each_price+'/sale';

		$modal.load(url, '', function () {

			$modal.modal();

		});

	}, 1000);

});



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