
<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/startsales";
		alert(" printing...........");
    }else {

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

		    // document.body.innerHTML = originalContents;

	}
}
	</script>

         <script type="text/javascript">
  
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
		
		
		
    </script>   
  <style type="text/css">
  
  

    #printable { display: none; }
#print{  	


    background-repeat: no-repeat;
	font-size;20px;
  
    width:100%; 


}

#sale{  	


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


}
    @media print
    {
    	#non-printable { display: none; }
    	#printableArea { display: block; font-size:16; width:100%; }
    }
    </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 salesreport</span>
                        <a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/startsales">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'];	
	 				echo $this->session->flashdata('deletemsg'); 

				echo $this->session->flashdata('msg'); 
								?>	
					<div class="row">
						<div class="col-md-12">
							
							<div class="panel-body">
	
									
				<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

             <thead>
         <tr>
									<th> Code</th>
                                        <th> Item Name</th>
                                              <th> Sale Type</th>  
                                              <th> B. price</th>   
											  <th> S. price</th>   

                                              <th> Qty</th>                        
											  <th>Dsc</th>                            

												<th>Total </th>
												<th> Profit </th>
													<th> 	Tax</th>
													    <th> Type</th>  

									       <th>Date sold</th>
										 
									

										    <th> Added by</th>  
		   <th id="non-printable"> More</th> 


                 </tr>
             </thead>
<?php

			
			if(is_array($allsales)) {

   foreach($allsales as $userrow){
 $code =  $userrow->invoice;
	  		$salesreport = $this->usermodel->viewproductsalesreportbycustomers($finalfromdate,$finaltodate,$type,$companyid,$code);



 if(is_array($salesreport)) {
	
    
             $totaltax=0; 
  $total=0; 
    $totalqty=0; 
							$totalprofit=0; 
  	foreach ($salesreport as $c): 

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

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

             ?>



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

              
  <td><?php echo $c->code ; ?></td>

  <td><?php echo $myproducts[0]['name']."-".$myproducts[0]['description'] ; ?></td>
    <td><?php echo $c->salestype ; ?></td>
   <td><?php echo $c->bprice ; ?></td>
	  <td><?php echo $c->sprice ; ?></td>
	  <td><?php echo $c->qty ; ?></td>
<td><?php echo $c->discount ; ?></td>
  <td><?php echo $c->amount ; ?></td>
      <td ><?php echo $profit;?></td> 
	  			       <td><?php echo $c->tax ; ?></td>

            <td><?php echo $c->type ; ?></td>
  <td><?php echo $c->dateposted	 ; ?></td>	

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

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

  ?></td>  
  
   <td  id="non-printable"> 

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


                                                <i class="glyphicon glyphicon-pencil"></i>
																Delete
                                                </a>
                                                        </li>
									
									
                                        <li class="divider"></li>
                                        
                                        <!-- teacher DELETION LINK -->
                                        
                                    </ul>
											<?php
										}
										?>
                                </div>
</td> 
         
             </tr>

	<?php endforeach;}}


	?>

								<tr border="1" background="green">
									<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></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>
									<td><input type="text" name="totalprofit" style="background:#999999 ; width:100px" readonly="true"  value="<?php if(isset($totalprofit)) {echo formatMoney($totalprofit, true);  }?>" class="form-field"/> </td>

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

									</td>
	<td colspan="3"></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>


















