

         <script type="text/javascript">
  
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
		
		
		
    </script>   
 <style type="text/css">
  
  
  .invoice-box table tr.heading td {
        background: #eee;
        border-bottom: 1px solid #ddd;
        font-weight: bold;
		height:auto;
		
		
    }
  

    #printable { display: none; }
#print{  	


    background-repeat: no-repeat;
	font-size;10px;

    width:100%; height:50px;



}
.doted{
    border: dotted 3px #000000;
}
table { border-collapse: collapse; }
td { padding: 5px; }
#maintable tr { border-bottom:1px dashed #494949; padding:0px;}


table{
    border-collapse:collapse;/*This property collapses borders together*/
}

#sale{  	
background-image:url(images/add.png) ;

    background-repeat: no-repeat;
  
    width:100px; height:50px;


}
#myalltitle { font-size: 2em; }
#alltitle{ font-size: 1em; }
	#mytitle { font-size: 1.4em; }

    
    {
		
    	#non-printable { display: none; }
    	#printableArea { display: block; font-size:10; width:100%; }
		  margin:0; 
		#receipt{
	font-style: normal;font-size: 1.5em;
	
	padding:0px;
	
}
    }
    </style>
 
 <div class="row">
  
   	

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

  
		<div class="panel panel-default" data-collapsed="0">
        	<div class="panel-heading" id="non-printable">
            	<div class="panel-title" id="redcolor" >
            		<i class="entypo-plus-circled"></i>
				 <span class="pull-right"> View sales report</span>
                        <a  id="non-printable"  class="btn btn-primary" href="<?php echo base_url();?>user/mysales">back  </a>
				 		 	<div class="pull-right"  >
<form name="print" method="post" action="">
 <input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('sortable_table')" value="print receipt!" />
</form></div>
            	</div>
            </div>
			<div class="panel-body">

			
	<div class="widget-content nopadding table_holder table-responsive" >				
				<?PHP
function formatMoney($number, $fractional=false) {
						if ($fractional) {
							$number = sprintf('%.2f', $number);
						}
						while (true) {
							$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
							if ($replaced != $number) {
								$number = $replaced;
							} else {
								break;
							}
							
						}
						return $number;
					}
 $session_data = $this->session->userdata('logged_in');

   
 	 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
	    $addproductaction=$this->usermodel->populatuserpermissionsdataarray('reports','add',$userid);

	 $updateaction=$this->usermodel->populatuserpermissionsdataarray('reports','update',$userid);
  $updatebuyingpriceaction=$this->usermodel->populatuserpermissionsdataarray('reports','update',$userid);
  $deleteaction=$this->usermodel->populatuserpermissionsdataarray('reports','delete',$userid);
    $viewreport=$this->usermodel->populatuserpermissionsdataarray('reports','view',$userid);
					  	      $dontshowtotal=$this->usermodel->populatuserpermissionsdataarray('cashiersales','dontshowtotal',$userid);

	 $returnclearedsales  =$this->usermodel->populatuserpermissionsdataarray('viewreturnsales','returnclearedsales',$userid);

	 				echo $this->session->flashdata('deletemsg'); 

				echo $this->session->flashdata('msg'); 
				 $myusers="";
				if( $user!="all"){
				$allusers=$this->usermodel->geteuser($user);
    $myusers=$allusers[0]['firstname'];
				}else{
					
					 $myusers="All Users";
				}
				
			$salesid = $userid.time();
				
				
				
				
				
				
				
								?>	
					<div class="row">
						<div class="col-md-12">
							
							<div class="panel-body">
	
	
		<?php
	   if($returnclearedsales==true){
		   ?>
		   
										 <a  id="more"  class="btn btn-danger" href="<?php echo base_url();?>Systemusers/resetmysalesall?randomitemidentifier=<?php   {echo  $salesid;}  ?>&type=retail&view=user/viewsales "> <span class="glyphicon glyphicon-trash">Reverse All</span> </a>

			<?php
	   }


?>			
	
	
	
	
	
	
	
	
			
				<table class="table" id="sortable_table" border="1">			

             <thead>
			 

			 	  <tr>
			 <th colspan="10"><center>
			 
			 
			 <?php  if(isset($configuration[0]['businessname'])) {echo   $configuration[0]['businessname']; }
			   $TIMEOFREPORT=date("d/m/Y H:i:s a");
			 ?>

			 <B><?PHP if(isset($reporttype)) {echo   $reporttype; } ?><BR> 
		Report For  <?PHP if(isset($myusers)) {echo   $myusers; } ?>	 Between  <?php  if(isset($finalfromdate)) {echo   date("d/m/Y H:i:s", strtotime($finalfromdate)); }?>  To  <?php  if(isset($finaltodate)) {echo     date("d/m/Y H:i:s", strtotime($finaltodate));; }?>   </B><br>
			 Report was run on <?php echo  date("d/m/Y H:i:s");?>
									<br>Name----------------------Date--------------------Signature----------------</span>

			</th>
	
			 </center>
			 </tr>
         <tr>
									<th > Code</th>
                                        <th> Item Name</th>
										
										<?php 
										
										if($group!="yes"){
											?>
											
											  <th> Sale Type</th>  
											  <th> S. price</th>  
											  	  <th  id="non-printable">Dsc</th>    
											<?php
										}
										
										?>
                                            
                                          
											 

                                              <th> Qty</th>                        
										                        

												<th>Total </th>
												
									
												
											
													   
											
									       <th>Date sold</th>
										 
									

										    <th> Sold by</th>  


                 </tr>
             </thead>
<?php




 if(!is_array($salesreport)) {
				    echo '<div class="alert alert-danger text-center">No data found</div>';

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

 {


   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 
  $total=0; 
  		  $totaltax=0; 					

    $totalqty=0; 
							$totalprofit=0; 
  	foreach ($salesreport as $c): 

		 $bprice=$c->bprice;
									$sprice=$c->sprice;
									$qty=$c->qty;

							$profit=((double)$sprice-(double)$bprice)*$qty;

             ?>



             <tr>
                
            <?php 
$id=$c->id;
 //$total=$total+$c->myamount;
 
 $totalprofit=(double)$totalprofit+(double)$profit;
 $totalqty= (double)$totalqty+(double)$qty;
$mycode="";
$tax=$c->tax;
 $totaltax= (double)$totaltax+ (double)$tax;
$mycode=$c->code;
$myproducts=$this->usermodel->geteproductbyid($mycode);

	$myinvoice=$c->invoice;
 $recipt = $this->usermodel->populateallarray('sales','invoice',$myinvoice);
		 	  $receiptno=$recipt[0]['id'];	




?>

														  <td>
  
  		   <a  id="non-printable" class=" btn-default" target="_blank"  href="<?php echo base_url();?>user/searchinvoice?code=<?php   if(isset($c->invoice )) {echo $c->invoice ; } ?>&view=userdata/allinvoices"> 		
<?php 

	echo $c->code  ;

	echo "<br> RCT- ". $receiptno;

  ?>
  </a>
  
   <span id="myprint">
<?php 

	echo $c->code  ;

	echo "<br> RCT- ". $receiptno;

  ?>
						 </span>
  
  </td>
		



              
 

  <td><?php echo $myproducts[0]['name']."-".$myproducts[0]['description'] ; ?></td>
  
  	<?php 
										
										if($group!="yes"){
											?>
											
											   <td><?php echo $c->salestype ; ?></td>

	  <td><?php echo $c->sprice ; ?></td>
	  <td  id="non-printable"><?php echo $c->discount ; ?></td>
											<?php
										}
										
										?>
                                            
                                          
 
	  <td><?php echo $c->qty ; ?></td>

  <td><?php //echo $c->myamount ; 
  
  
  
		if($group!="yes"){
			  $ttprice=(double)$c->sprice* (double)$c->qty ;
					$total=(double)$total+(double)$ttprice;	
				echo formatMoney($ttprice, true) ;
					
			}else{
			
				
				echo formatMoney($c->myamount, true) ;
					  $total=(double)$total+(double)$c->myamount;
	
				
				
			}
  
  
  ?></td>
      
	  
	  
  <td><?php echo $c->dateposted	 ; ?></td>	

 <td><?php 
//if($user=="all"){
	//echo "Everyone";
//}else{
	


 $userids= $c->userid ;

$myuser=$this->usermodel->geteuser($userids);
   echo $myname=$myuser[0]['firstname'];
//}
  ?></td>  
  
 
             </tr>

	<?php endforeach;} ?>

		<?php
 if( $dontshowtotal==true){
	 ?>
											 


	 
	  <?php
}else{
	
	
?>


								<tr border="1" background="green">
							
									
									  	<?php 
										
										if($group!="yes"){
											?>
	<td colspan="5"><b>Total Amount</b></td>												<td ><input type="text" name="total" style="background:#999999 ; width:100px" readonly="true"  value="<?php if(isset($totalqty)) {echo $totalqty;   }?>" class="form-field"/> </td>

				<td><input type="text" name="total" style="background:#999999 ; width:100px" readonly="true"  value="<?php if(isset($total)) {echo formatMoney($total, true);  }?>" class="form-field"/> </td>


											<?php
										}else{
											?>
											
											
												<td colspan="2"><b>Total Amount</b></td>
												<td ><input type="text" name="total" style="background:#999999 ; width:100px" readonly="true"  value="<?php if(isset($totalqty)) {echo $totalqty;   }?>" class="form-field"/> </td>

				<td><input type="text" name="total" style="background:#999999 ; width:100px" readonly="true"  value="<?php if(isset($total)) {echo formatMoney($total, true);  }?>" class="form-field"/> </td>

	
											
											
										<?php	
										}
										
										?>


									
	<td colspan="4"></td>								
</tr>
	
	
	
              <?php 
			  }
			 }
			  ?>

        </table>
		
	</div>

			<div id="deleteModel" 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="sales_order">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="user/startsales">
 <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>
		</div>
  
  </div>
			
			
			
		
		
  

 
</div>




<script>
	function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

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

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

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

		    // document.body.innerHTML = originalContents;

	}
}
	</script>














