<link href="<?php echo base_url(); ?>assets/autocomplete/jquery-ui.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/autocomplete/ui.theme.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/autocomplete/autocomplete.css" rel="stylesheet">
    <script src="<?php echo base_url(); ?>assets/autocomplete/jquery-ui.min.js"></script>

        <script type="text/javascript">  
		
			   $(this).ready( function() {  
            $("#product").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
					                        url: "<?php echo base_url(); ?>Systemusers/branchlookup",  

                            // url: "<?php echo base_url(); ?>/Systemusers/productlookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
		
		 $(document).on("click", "#managebtnreturn", function()
        {
          var returnid = $(this).data('id');
		  $("#returnid").val(returnid); 
		  
		     var qty = $(this).data('qty');
		  $("#qty").val(qty); 
		    var serial = $(this).data('serial');
		  $("#serial").val(serial); 
		   
        });
		
		
		
		
			$(this).ready( function() {  
            $("#mysupplier").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
					//  url: "<?php echo base_url(); ?>Systemusers/customerSaleslookup",  

                       url: "<?php echo base_url(); ?>Systemusers/customerlookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
		
		
			$(this).ready( function() {  
            $("#mysupplier2").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
					//  url: "<?php echo base_url(); ?>Systemusers/customerSaleslookup",  

                       url: "<?php echo base_url(); ?>Systemusers/customerlookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
		
    </script> 
	
	<script>
	function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;
  var printing = document.getElementById('printing');

     document.body.innerHTML = printContents.fontsize(16);
     window.print();

	 if( window.print()) {
		 if(printing=true){
			 
			  window.location.href = "../user/logout";

		 }else{
			         window.location.href = "../user/viewdamages";
 		alert(" printing...........");

		 }
    }else {

	
		      return      window.location.href = "../user/viewdamages";

		    // document.body.innerHTML = originalContents;

	}
}
	</script>

 
 <div class="row">
  
   	

   	<div class="col-md-12">

  
		<div class="panel panel-default" data-collapsed="0">
        	<div class="panel-heading">
            	<div class="panel-title" id="redcolor" >
            		<i class="entypo-plus-circled"></i>
				 <span class="pull-right"> View damages  </span>
	  <a data-toggle='modal' data-target='#addModal' class="btn btn-primary">Add Damaged product </a>
				 	 <a data-toggle='modal' data-target='#productModal' class="btn btn-default">View Damaged Products By date  </a>

<form name="print" method="post" action="">
 <input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('printableArea')" value="Print!" />
</form>
		
            	</div>
            </div>
			<div class="panel-body">

			
	<div class="widget-content nopadding table_holder table-responsive" >				
				<?PHP
 $mydate=date("Y-m-d H:i:s");
 echo $this->session->flashdata('deletemsg'); 

				echo $this->session->flashdata('msg'); 
				
				
 $mydate = date('Y-m-d 23:59:59');
   $fromdate=date("Y-m-d 00:00:00");

								?>	
					<div class="row">
						<div class="col-md-12">
							<div class="col-md-12">
        <?php 
		$mypage=0;
		if(isset($page)) {$mypage=$page;}else{$mypage=0;}
        $attr = array("class" => "form-horizontal", "role" => "form", "id" => "search", "name" => "search");
        echo form_open("user/searchfordamageditems", $attr);?>
            <div class="form-group">

                <div class="col-md-3">
                    <input class="form-control" autofocus id="searchterm" name="searchterm" placeholder="Search for product by name, code,description.." type="text" value="<?php echo set_value('searchterm'); ?>" />
                </div>
				
					   <div class="col-md-2">
				   <select class="form-control"name="searchtype"  >
	
	<option value=""  >---Select way of search items---</option>

   <option value="all" selected="selected" >All/General</option>

   <option value="Specific"  >Specific item</option>

   

</select>		
	
                </div>
                <div class="col-md-3">
                    <input id="btn_search" name="btn_search" type="submit" class="btn btn-default" value="Search" />
                    <a href="<?php echo base_url(). "user/viewdamages"; ?>" class="btn btn-default">Refresh</a>

			   </div>
				 
            </div>
        <?php echo form_close(); ?>



        </div>
					<div id="printableArea" style="width:100%;margin:0" >
							<div class="panel-body">
	
									<table    width="100%" border="1">


             <thead>
         <tr>
  									<th>Product code </th>
							
			<th>Serial No </th>

						<th>Item Name </th>

													<th>From </th>
		<th> Recorded by </th>
		<th>Responsible Person  </th>
			<th> Description </th>
						<th> Supplier </th>

			<th> Original </th>
			<th> Qty </th>
			<th> Balance </th>
			<th> B.Price </th>
			<th> TT B.Price </th>
			
			
			
			<th> Date </th>
				
			<th>More</th>
		


                 </tr>
             </thead>
<?php
 if(!is_array($viewdamages)) {
				    echo '<div class="alert alert-danger text-center">There was no purchase found in the system</div>';

			 }else{
 if(!is_array($viewdamages)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='1'>";
    
       echo '<div class="alert alert-warning text-center">There no records found..</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
  $ttqty=0;
  $ttbrice=0;
  	foreach ($viewdamages as $c): 

		 

             ?>



             <tr>
                
            <?php 
$id=$c->id;

$mycode=$c->product;
  $codedate=$this->usermodel->populateallarray('products','code',$mycode);
	
 $name=$codedate[0]['name'];
  $description=$codedate[0]['description'];

 $supplier=$codedate[0]['supplier'];
$myinvoice=$c->invoice ;


$ttqty=(double)$ttqty+(double)$c->qty;
  $ttbrice=(double)$ttbrice+(double)$c->ttbrice;

?>


              
  <td><?php echo $c->product ; ?></td>
    <td><?php echo $c->user ; ?></td>

    <td><?php echo $name."-".$description ; ?></td>

    <td><?php 
	
								 
 
					// $branch="";
					 $branch=$c->expendituretype;

					 $branch= $this->usermodel->populateall('branch','id',$branch);



if(is_array($branch)) {

   foreach($branch as $branchrow){

   echo $branchrow->name;
 
 
}} else {
    echo 'Store';
}
	
?>
	
	
</td>

	 <td><?php  $userids= $c->userid ;

$myuser=$this->usermodel->geteuser($userids);
   echo $myname=$myuser[0]['firstname'];

  ?></td>
    <td><?php echo $c->incharge ; ?></td>
   <td><?php echo $c->details ; ?></td>
   
    <td><?php 

$mysupplier=$this->usermodel->geteuser($c->supplier);
 
   
   
if($mysupplier[0]['company']!=""){
	
	  echo $mysupplier[0]['company'];
}else{
	  echo $mysupplier[0]['firstname'];
	
}
  ?></td>
   
	  <td><?php echo $c->original ; ?></td>
	   <td><?php echo $c->qty ; ?></td>
	    <td><?php echo $c->balance ; ?></td>
		
		   <td><?php echo $c->buyingprice ; ?></td>
	    <td><?php echo $c->ttbrice ; ?></td>
		
		
		
	  <td><?php echo $c->datedamaged ; ?></td>
	 <td> 

 
 
					<div class="btn-group">
                                    <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown">
                                        More <span class="caret"></span>
                                    </button>
								
                                    <ul class="dropdown-menu dropdown-primary pull-right" role="menu">
                                        
                                        <!-- teacher EDITING LINK -->
                                      
											<?php
										if($usertype=="admin"){
											
											?>
											<!--
											  <li> 
										 <a class="btn btn-danger managebtn" id="managebtndelete"		 data-id='<?php echo  $c->id;?>'    data-toggle='modal' data-target='#deleteModal<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Cancel
                                                </a>
                                                        </li>
														
														-->
									
									
                                        <li class="divider"></li>
                                        
													<li> 
										 <a class="btn btn-warning managebtn" id="managebtnreturn"	data-serial='<?php echo  $c->user;?>' data-qty='<?php echo  $c->qty;?>'	 data-id='<?php echo  $c->id;?>'    data-toggle='modal' data-target='#returnModal<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Return
                                                </a>
                                                        </li>
		<?php
										}
										?>

   <li class="divider"></li>

     <li> 
				<a  id="more" class=" btn-success" target="_blank"   href="<?php echo base_url();?>user/searchJE?searchterm=<?php   {echo  $myinvoice;}  ?> ">
								 
																							 

                                                <i class="glyphicon glyphicon-pencil"></i>
															View	GL Transactions
                                                </a>
																		
										</li>														
                                    </ul>
									
                                </div>
</td>
     	
                  
             </tr>

	<?php endforeach;} ?>

              <?php }?>
			  

			  
			 <tr>
		
			 <td COLSPAN=8> 	 <b>TT QTY </b></TD>
 <td>	 <b> <?php if(isset($ttqty)) {echo $ttqty;}; ?> </b></TD>
 <td COLSPAN=2>	 <b>TT Value </b></TD>
  <td> 	 <b><?php  if(isset($ttbrice)) {echo $ttbrice;} ; ?> </b></TD>

  
</tr>		 
			  
			  
			  

        </table>
		<div class="col-md-12 text-center">    <?php echo $links; ?>
					   		<span style="color:red; font-size:20px"><?php  echo $total_rows. "  Products damaged in the system. " ;?>    </span>

        
        </div>
	</div>
</div>
	
	<div id="deleteModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Delete</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to delete this item? </h3>
      </div>
      <div class="modal-footer">
	  	

     
		<?PHP
				$session_data = $this->session->userdata('logged_in');
 echo $this->session->flashdata('deletemsg'); 

		
                 echo form_open('user/deletebyid' , array('class' => 'form-horizontal ', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>
 <input type="hidden" id="table"name="table" class="table" placeholder="view" value="damages">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="user/viewdamages">
 <input type="hidden" id="itemid1"name="itemid" class="itemid" placeholder="itemid" value=""><br>
 <button type="button" class="btn btn-success" data-dismiss="modal">No</button>
 		  	         <button type="submit" name="btn_delete" value="deletebyid" class="btn btn-danger"> Delete  </button>

	<?php echo form_close();?>
      </div>
    </div>

  </div>

  </div>		
	
	
	
	
	
	<div id="returnModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Return</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to return this item? </h3>
      </div>
      <div class="modal-footer">
	  	

     
		<?PHP
				$session_data = $this->session->userdata('logged_in');
 echo $this->session->flashdata('deletemsg'); 

		
                 echo form_open('user/returndamageditems' , array('class' => 'form-horizontal ', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>
 <input type="hidden" id="serial" name="serial" class="serial" placeholder="serial" value="">

 <input type="hidden" id="qty" name="qty" class="qty" placeholder="qty" value="">
 <input type="hidden" id="table"name="table" class="table" placeholder="view" value="damages">


 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="user/viewdamages">
 <input type="hidden" id="returnid"name="itemid" class="returnid" placeholder="returnid" value=""><br>
 <button type="button" class="btn btn-success" data-dismiss="modal">No</button>
 		  	         <button type="submit" name="btn_delete" value="deletebyid" class="btn btn-danger"> Yes  </button>

	<?php echo form_close();?>
      </div>
    </div>

  </div>

  </div>		
	
	
				
				<div id="productModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">View Damaged products by date</h4>
      </div>
      <div class="modal-body">
      
	  	




				<?PHP
//$session_data = $this->session->userdata('logged_in');



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/viewdamagedproducts' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>








	
	
	
  <div class="form-group">
    <label for="inputbranch" class="col-sm-2 control-label">Branch</label>
    <div class="col-sm-10">
	<select class="form-control" name="branch"  id="branch" required>
	
	
	<option value=""  >---Select Branch/Counter-</option>
						<option value="Main"  >Main Store</option>
					
						<option value="all"  selected="selected" >--All/Any--</option>

	
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

   //echo $courserow->coursename;
    ?>
					<option  value="<?=  $maincategoryrow->id;   ?>"><?=  $maincategoryrow->name; ?></option>



	<?php

}} else {
    echo 'No main counter available.';
}
	
?>
</select>
		

		
	</div>
  </div>
	
	





supplier





	  <div class="form-group">
    <label for="inputcode" class="col-sm-2 control-label">Product code</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="code" id="id" autofocus value="<?php echo set_value('code',"all"); ?>" class="form-control" required placeholder="Enter code or name">
		 
				
		<span class="text-danger"> <?php echo form_error('code'); ?>
		
		</span>
	</div>
  </div>
  
	
	
	
	
	
	
	
  <div class="form-group">
    <label for="inputfromdate" class="col-sm-2 control-label">From Date </label>
    <div class="col-sm-10">

		  		<input type="text" name="fromdate" value="<?php echo set_value('fromdate',$fromdate); ?>" class="form-control" required placeholder="Enter start date">
		 
				
		<span class="text-danger"> <?php echo form_error('fromdate'); ?>
		
		</span>
	</div>
  </div>
  
  	<div class="form-group">
    <label for="inputtodate" class="col-sm-2 control-label">	To Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="todate" value="<?php echo set_value('todate',$mydate); ?>" class="form-control" required placeholder="Enter End date">
		 
				
		<span class="text-danger"> <?php echo form_error('todate'); ?>
		
		</span>
	</div>
  </div>
  
    
       	 		  		<input type="hidden" name="type" value="all" class="form-control" required placeholder="Enter all">

	  <div class="form-group">
    <label for="inputsupplier" class="col-sm-2 control-label">Supplier</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="supplier"   id="mysupplier2" value="<?php echo set_value('supplier',"all"); ?>" class="form-control" required placeholder="Enter supplier name or leave it as all">
		 
				
		<span class="text-danger"> <?php echo form_error('supplier'); ?>
		
		</span>
	</div>
  </div>
  
	
	

	
	 <div class="form-group" >
    <label for="inputdownload" class="col-sm-2 control-label">Download?</label>
    <div class="col-sm-10">
	<select class="form-control" name="download" required>
	
	<option value=""  >---Select your option---</option>

		<option value="no" selected="selected" >--no--</option>
			<option value="yes"  >--Yes--</option>

</select>
		

	</div>
  </diV>

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="event" name="btn_addevent" class="btn btn-primary"> View   </button>

    </div>
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </div>
    </div>
	

	
	
	<div id="addModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Add new damaged products </h4>
      </div>
      <div class="modal-body">
      
	  	

				<?PHP
//$session_data = $this->session->userdata('logged_in');



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/adddamages' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>

 <div class="form-group">
    <label for="inputbranchname" class="col-sm-2 control-label">Counter</label>
    <div class="col-sm-10">
	<select class="form-control" name="branchname"  id="branchname" required>
	
	
	<option value=""  >---Select Branch/Counter Name--</option>
<?php
									 if( $viewallaction==true){
										 ?>
					<option value="all"  >All branches/Counters</option>
									<?php
									 }
							
	?>
	
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

   //echo $courserow->coursename;
    ?>
					<option selected="selected" value="<?=  $maincategoryrow->id;   ?>"><?=  $maincategoryrow->name; ?></option>



	<?php

}} else {
    echo 'No main counter available.';
}
	
?>
</select>
		

		
	</div>
  </div>
  
     <div class="form-group">
    <label for="inputmethod" class="col-sm-2 control-label">Search Method?</label>
    <div class="col-sm-10">
	<select class="form-control" name="method" required>
	
	<option value=""  >---Which method do you want to search with?---</option>
	<option value="No" selected="selected" > No serial Numbers(General)</option>
	<option value="Serial"  >Search using serial Numbers</option>

	


</select>
		

	</div>
  </div>
  	







<div class="form-group">
    <label for="inputproduct" class="col-sm-2 control-label">	Product name :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" required name="product" id="product" value="<?php echo set_value('product'); ?>" class="form-control"  placeholder="Search item by name, code,serial No etc">
		 
				
		<span class="text-danger"> <?php echo form_error('product'); ?>
		
		</span>
	</div>
  </div>
	<div class="form-group">
    <label for="inputqty" class="col-sm-2 control-label">Quantity :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="qty" value="<?php echo set_value('qty',1); ?>" class="form-control" required placeholder="Enter  Quantity Damaged">
		 
				
		<span class="text-danger"> <?php echo form_error('qty'); ?>
		
		</span>
	</div>
  </div>
  
	<div class="form-group">
    <label for="inputincharge" class="col-sm-2 control-label">Person incharge </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="incharge" value="<?php echo set_value('incharge'); ?>" class="form-control" required placeholder="Enter Person incharge name">
		 
				
		<span class="text-danger"> <?php echo form_error('incharge'); ?>
		
		</span>
	</div>
  </div>

  					 

  	<div class="form-group">
    <label for="inputdatedamaged" class="col-sm-2 control-label">Date damaged</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="datedamaged" value="<?php echo set_value('datedamaged', $mydate); ?>" class="form-control" required placeholder="Enter Date damaged ">
		 
				
		<span class="text-danger"> <?php echo form_error('datedamaged'); ?>
		
		</span>
	</div>
  </div>
  
   
  
  
  
  
     <div class="form-group">
    <label for="inputfrom" class="col-sm-2 control-label">From?</label>
    <div class="col-sm-10">
	<select class="form-control" name="from" required>
	
	<option value=""  >---Where do you want to deduct  product from?---</option>

	
	<?php 
					 

					 $branch= $this->usermodel->populateall('branch','companyid',$companyid);



if(is_array($branch)) {

   foreach($branch as $branchrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $branchrow->id;   ?>"><?=  $branchrow->name; ?></option>



	<?php

}} else {
    echo 'No branch available.';
}
	
?>

	<option value="Main"  > Main Store?</option>

</select>
		
						<span class="text-danger"><?php echo form_error('from'); ?>

	</div>
  </div>
  	
  
  
  
  
  
  
 				
					  <div class="form-group">
    <label for="inputsupplier" class="col-sm-2 control-label">Supplier name</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="supplier" id="mysupplier" autofocus value="<?php echo set_value('supplier',"all"); ?>" class="form-control" required placeholder="Enter supplier name">
		 
				
		<span class="text-danger"> <?php echo form_error('supplier'); ?>
		
		</span>
	</div>
  </div>
			
  
  
  
  
	<div class="form-group">
    <label for="inputdetails" class="col-sm-2 control-label">	Remarks </label>
    <div class="col-sm-10">

				<textarea name="details" value="<?php echo set_value('details'); ?>"  class="form-control"  placeholder="Enter remarks"></textarea>
			
		<span class="text-danger"> <?php echo form_error('details'); ?>
		
		</span>
	</div>
  </div>
		

	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="damage" name="btn_damage" class="btn btn-primary"> Add Damaged Product   </button>

    </div>
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </div>
    </div>			
									
									
									
									
							</div>
						</div>
				

			
			</div>
		</div>
  
  </div>
	
		
			
		
		
  

 
</div>

	


















