<style type="text/css">
.fa-3x {
  font-size: 2em !important;
}
.report_view_th{
	background-color:#428bca;
	color:#fff !important;
	font-size:14px;	
}
.table-responsive td{
	font-size:14px;	
}
h4{
	font-size:13px;
}
</style>

	<?php $this->load->view("common/header"); ?>
	<!-- end: HEAD -->
     
		<!-- end: CSS REQUIRED FOR THIS PAGE ONLY -->
	<!-- end: HEAD -->
	<!-- start: BODY -->
	<body>
		<!-- 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="<?php echo base_url('dashboard'); ?>">
										 Dashboard 
									</a>
								</li>
								<li>
									
										 Store note 
								
								</li>
                               
								<li class="active">
									Manage
								</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">  
                               <?php  
							   $message = $this->session->flashdata('message');
							   if($message){ ?>
                               	<div class="alert alert-success">
									<button type="button" class="close" data-dismiss="alert">×</button>
<?php echo $message ?> </div>
                               		
                               <?php
                               }
							    ?>
                               
                                 
							</div>

                            
						</div>
					</div>
					<div class="modal-footer" style="margin-bottom:10px;">
                  
                  <div class="form-group">
                    <label>Vehicle *</label>
                      <select  id="vehicle_id" class="form-control" name="vehicle_id">
                        <option>-Select-</option>
                        <?php 						
						foreach ($vehicle_list as $vh)
							{
								$select="";
								if($vh['vehicle_id']==$row['vhicle_id']){
									$select="selected";
								}
							?>
                        <option  <?php echo $select;?> value="<?php echo $vh['vehicle_id'];?>"><?php echo $vh['vehicle_name'];?>-<?php echo $vh['driver_name'];?></option>
                        <?php }  ?>
                    </select>
                </div>
                  
                  <a onClick="sales_rep_details_print_2()" class="btn btn-info pull-right"> Print Loading Sheet </a>
                  
                </div>
					<!-- end: PAGE HEADER -->
					<!-- start: PAGE CONTENT--> 
                    <!-- start grid -->
                       <?php  //print_r($store_note_list); ?>
                    <?php foreach($store_note_list as $stn_info ){ ?>
                    
                
                   <?php  //print_r($stn_info); ?>
                    <div class="row">
                        <?php //echo "p1"; ?>
						<div class="">
						   
							<!-- start: DYNAMIC TABLE PANEL -->
							<div class="panel panel-default">
								<div class="panel-heading">
							
									<i class="fa fa-external-link-square"></i>
									Store note Number <?php echo $stn_info['stn_id'] ?>
									<div class="panel-tools" style="top:2px;">
										
											
									</div> <!--panel-tools-->
								</div> <!--panel-heading-->
								<div class="panel-body">
									 
<div class="well well-sm">                      

<div class="col-xs-4 border-right">
<div class="col-xs-2"><i class="fa fa-3x fa-file-text-o padding010 text-muted"></i></div>
<div class="col-xs-10">
<h4 class="">Invoice No : <?php echo $stn_info['stn_code'];?></h4>
<p>Date: <?php echo display_date_time_format($stn_info['stn_date_time'])?></p>
</div>
<div class="clearfix"></div>
</div>

<div class="col-xs-4 border-right collapse">
<div class="col-xs-2"><i class="fa fa-3x fa-user padding010 text-muted"></i></div>
<div class="col-xs-10">
<h4 class=""><?php //echo $customer_details['cus_name']; ?></h4>
<?php //echo $customer_details['cus_address']; ?><br>
<p></p>
Tel:  <?php //echo $customer_details['cus_phone']; ?><br>
Email: <?php //echo $customer_details['cus_email']; ?> </div>
<div class="clearfix"></div>
</div>

<div class="col-xs-4">
<div class="col-xs-2"><i class="fa fa-3x fa-building-o padding010 text-muted"></i></div>
<div class="col-xs-10">
<h4 class=""><?php echo $stn_info['name']; ?></h4>

<!--<?php echo $stn_info['address']; ?><p></p>
Tel: <?php //echo $stn_info['phone']; ?><br>
Email: <?php //echo $stn_info['email']; ?> --></div>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
</div> <!--col-xs-4-->



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

<div class="clearfix"></div>
</div> <!--col-xs-4"-->
<div class="clearfix"></div>






<div class="table-responsive">
<table class="table table-bordered table-hover table-striped print-table order-table">
<thead>
<tr class="report_view_th">
<th>No</th>
<th>Description (Code)</th>
<th>QTY</th>
<!--<th>Issued <br>QTY</th>
<th>pending <br> QTY </th>-->
<th style="padding-right:20px;">Hand Over to Lorry</th>
<th style="text-align:center; vertical-align:middle;">Hand Over To Customer</th> 
<th style="padding-right:20px;">Status</th>
</tr>
</thead>
<tbody>
 <?php 
 $tmpcount=0;
 $tmptot=0;
 $obj = new store_notes_model();
$stn_items=$this->store_notes_model->get_store_note_items_all_in_one($stn_info['warehouse_id'],$stn_info['stn_no']);
 //echo "-----";
 //print_r($stn_items);
 
  foreach ($stn_items as $row)
 {
	 $tmpcount++;
	 
 ?>  
<tr>
<td style="text-align:center; width:40px; vertical-align:middle;"><?php echo $tmpcount ?></td>
<td style="vertical-align:middle;"><?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']; ?>

</td>
<td style="text-align:center; vertical-align:middle;">
    <p style="text-align:left; vertical-align:middle;">Total Quantity: <?php echo $row['quantity']; ?></p>
    <p style="text-align:left; vertical-align:middle;">Already issued quantity:
    <?php $issued_qty = $this->Hw_Delivery_Model->get_issued_qty($row['id']);
        print_r($issued_qty);
    ?>
    </p>
     <input type="text" id="inp_<?php echo $row['id'] ;?>"> / <?php echo number_format($row['quantity']-$issued_qty, 2, '.', ',') ?> <?php if(($row['quantity']-$issued_qty)>0){ ?> <button onClick="update_issue_qty(<?php echo $row['id'] ;?>)">Issue</button> <?php } ?> </td>
<!--<td><?php echo number_format(0, 2, '.', ',') ?></td>-->
<!--<td style="text-align:right; padding-right:10px;"><?php echo number_format($row['quantity'], 2, '.', ',')?> </td>-->
<td style="text-align:right; padding-right:10px;">
<div class="col-sm-12" style="margin-right:2%;">
                    <div class="form-group">
<label>Vehicle *</label>
                      <select   id="item_veh_id_<?php echo $row['id']; ?>" class="form-control" name="vehicle_id" onChange="update_vehicle(this.value,<?php echo $row['id'] ;?>)">
                        <option value="">Customer Direct Issuue</option>
                        <?php 						
						foreach ($vehicle_list as $vh)
							{
								$select="";
								if($vh['vehicle_id']==$row['vhicle_id']){
									$select="selected";
								}

								?>
							
                        <option  <?php echo $select;?> value="<?php echo $vh['vehicle_id'];?>"><?php echo $vh['vehicle_name'];?>-<?php echo $vh['driver_name'];?></option>
                        <?php }  ?>
                      </select>
                    </div>
                  </div>
</td>
<td style="text-align:right; padding-right:10px;">

<div class="col-sm-12" style="margin-right:2%;">
 <div class="form-group">
<label>Hand Over ? *</label>
                      <select  id="customer_issued" class="form-control" name="customer_issued" onChange="update_customer_issue(this.value,<?php echo $row['id']; ?>)" >
						<?php 
						$select="";
						if($row['customer_issued']==1){
							$select="selected";
						}
						?>
						<option value="0">No</option>
						<option  <?php echo $select;?> value="1">Yes</option>
                      </select>
                    </div>
                  </div>

</td>
<td style="text-align:right; padding-right:10px;">
<?php if($row['customer_issued']==1){?>
	<span class="btn btn-success">Competed</span>
<?php } else{?>
<span class="btn btn-warning">Pending</span>
<?php } ?>

</td>
</tr>
<?php }?>
</tbody>


</table>
</div> <!--table-responsive-->


<div class="col-sm-3" style="margin-right:2%;">
 <div class="form-group">
     <hr>
<label>Completed ? *</label>
                      <select  id="customer_issued_<?php echo $row['id']; ?>" class="form-control" name="customer_issued" onChange="update_store_note(this.value,<?php echo $stn_info['stn_id']; ?>)" >
						<?php 
						$select="";
						if($stn_info['st_note_status']==1){
							$select="selected";
						}
						?>
						<option value="0">No</option>
						<option  <?php echo $select;?> value="1">Yes</option>
                      </select>
                    </div>
                  </div>
                  
                  <div class="col-sm-5" style="margin-right:2%;">
 <div class="form-group">
     <hr>

                   <?php if($stn_info['st_note_status']==1){ ?>
                   Completed By : <?php echo $stn_info['user_first_name']; ?><br>
                   Completed Date Time : <?php echo $stn_info['completed_date_tiime'];?>
                   <?php } ?>
                    </div>
                  </div>



<div class="clearfix"></div>
<p></p>
<div class="well well-sm col-xs-6 pull-right collapse">                      

<script> //alert();</script>
<div class="col-xs-10">
<p>
<?php //echo $tmptot;?><br>

Created by : <?php echo $this->session->userdata('ss_user_first_name'); ?> (<?php echo $this->session->userdata('ss_user_group_name'); ?>) </p>

<p>Date:<?php echo display_date_time_format($stn_info['stn_date_time'])?></p>
 </div>
<div class="clearfix"></div>

<div class="clearfix"></div>
</div> <!--well well-sm col-xs-6 pull-right-->


<div class="clearfix"></div>
<!-- end payment list-->



<div class="buttons">
<div class="btn-group btn-group-justified">

<!--<div class="btn-group"><a title="" class="tip btn btn-primary tip" data-target="#myModal" data-toggle="modal" href="http://sma.tecdiary.org/sales/add_payment/2" data-original-title="Add Payment"><i class="fa fa-money"></i> <span class="hidden-sm hidden-xs">View Payment</span></a></div>-->
<!--<div class="btn-group"><a title="" class="tip btn btn-primary tip" href="<?php echo base_url('hw_delivery/manage?id=').$stn_info['stn_id'] ;?>" data-original-title="Add Delivery"><i class="fa fa-truck"></i> <span class="hidden-sm hidden-xs">Add Delivery</span></a></div>-->

<!--<div class="btn-group" onClick="fbs_click(<?php echo $stn_info['stn_id']; ?>)"><a title="" class="tip btn btn-primary" data-original-title="Print"><i class="fa fa-print"></i> <span class="hidden-sm hidden-xs">Print</span></a>-->
</div>
 
</div>
</div> <!--buttons-->
                                     
                                   
								</div> <!--panel-body-->
								   <?php } ?>             
							</div><!--panel-->
							    
					
							
						</div> <!--col-md-12-->
					</div> <!--row-->

					
                    <!-- end grid -->

			</div>
			<!-- end: PAGE -->
		</div>
		<!-- end: MAIN CONTAINER -->
		<!-- start: FOOTER -->
		<div class="footer clearfix">
			<div class="footer-inner">
				2014 &copy; clip-one by cliptheme.
			</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>

		<!-- 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 -->

		<!-- start: MAIN JAVASCRIPTS -->
		<?php $this->load->view("common/footer"); ?>
		<!-- end: MAIN JAVASCRIPTS -->

        
		<!-- end: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY -->
<!-- start: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY -->
		
       <script src="<?php echo asset_url(); ?>plugins/jQuery-lib/2.0.3/jquery.min.js"></script>
		<script type="text/javascript" language="javascript" src="<?php echo asset_url(); ?>js/jquery.dataTables.js"></script>

		<!-- end: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY -->
		<script>
			jQuery(document).ready(function() {
				TableData.init();
				//Main.init();
				//TableData.init();
				//UIModals.init();
			});
		</script>
        
<script type="text/javascript" language="javascript" >
var j = jQuery.noConflict();
function loadGrid(){
	
	j('#employee-grid').DataTable().ajax.reload();
}
	jQuery(document).ready(function() {
		var dataTable = j('#employee-grid').DataTable( {
			"processing": true,
			"serverSide": true,
			"ajax":{
				url :"sales/list_sales", // json datasource
				type: "post",  // method  , by default get
				error: function(){  // error handling
					j(".employee-grid-error").html("");
					j("#employee-grid").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
					//$("#employee-grid_processing").css("display","none");
				}
			}
		} );
		
	} );
	
	

function update_vehicle(id,mst_id) {
	
	fields='';
	$.post( '<?php echo base_url() ?>hw_delivery/update_vehicle?vh_id='+id+'&mst_id='+mst_id, fields)
	.done(function( data ) {
		  var obj = jQuery.parseJSON(data);
			if(obj.error==1){
			}
			if(obj.error==0){
				displayNotice('page','Updated!');
			}			
	  });
	
}

function update_customer_issue(id,mst_id) {
	
	fields='';
	$.post( '<?php echo base_url() ?>hw_delivery/update_customer_issue?vh_id='+id+'&mst_id='+mst_id, fields)
	.done(function( data ) {
		  var obj = jQuery.parseJSON(data);
			if(obj.error==1){
			}
			if(obj.error==0){
				displayNotice('page','Updated!');
			}			
	  });
	  location.reload();
	 // alert(id);
	
}

function update_store_note(id,mst_id) {
	
	fields='';
	$.post( '<?php echo base_url() ?>hw_delivery/update_store_note?vh_id='+id+'&mst_id='+mst_id, fields)
	.done(function( data ) {
		  var obj = jQuery.parseJSON(data);
			if(obj.error==1){
			}
			if(obj.error==0){
				displayNotice('page','Updated!');
				 location.reload();
			}			
	  });
	 
	 // alert(id);
	
}
function update_issue_qty(mst_id) {
    var iq = $('#inp_'+mst_id).val();
    var hand_over = $('#customer_issued_'+mst_id).val();
    var veh_id = $('#item_veh_id_'+mst_id).val();
    
    if(iq > 0){
        fields='';
        $.post( '<?php echo base_url() ?>hw_delivery/update_issue_qty?iq='+iq+'&mst_id='+mst_id+'&veh_id='+veh_id, fields)
        .done(function( data ) {
            var obj = jQuery.parseJSON(data);
            if(obj.error==1){
			}
			if(obj.error==0){
				displayNotice('page','Issued!');
				window.location.reload();
			}			
	    });
    }
}

function sales_rep_details_print_2()
{
    var id = $('#vehicle_id').val();
	u=location.href;
	t=document.title;
	window.open('<?php echo base_url().'hw_delivery/print_delivary_sheet/'?>'+id,'sharer','toolbar=0,status=0,width=700,height=700, left=10, top=10,scrollbars=yes');return false;
}
</script>
	</body>
	<!-- end: BODY -->
</html>