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

    #myprint { 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%; }
		    	#myprint { 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="non-printable"  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;
					}
echo $this->session->flashdata('deletemsg'); 
	 $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);
   $fromdate=date("Y-m-d H:i:s a");


				echo $this->session->flashdata('msg'); 
								?>	
					<div class="row">
						<div class="col-md-12">
							
							<div class="panel-body">
	
									
				<table border="1"  width="100%">			

             <thead>
			 <tr>
			 <th colspan="2"><center>
			 <?php  if(isset($configuration[0]['businessname'])) {echo   $configuration[0]['businessname']; }?>

			 <B>Z-REPORT(DAILY) <BR> 
			 FROM  (<?php  if(isset($finalfromdate)) {echo   $finalfromdate; }?>)  TO  (<?php  if(isset($finaltodate)) {echo   $finaltodate; }?>)   </B><br>
			 Report was run on <?php  if(isset($fromdate)) {echo   $fromdate; }?>
			 </center>
			 <tr>
       
             </thead>
			 
<?php



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

	

    }else {
?>
    
             <?php 
  $total=0; 
    $totalcash=0; 
		  $totaltax=0; 
$totalmpesa=0;		  
$cashmpesa=0;

$totalcredit=0;		  
$totalcheque=0;
$totalvoucher=0;		  
$totalpoints=0;
$totalcard=0;		  




  	foreach ($salesreport as $c){
		
	


             ?>



            
                
            <?php 
$id=$c->id;
 $total=$total+$c->total;

 $myinvoice=$c->invoice ; 
 $view="";
$salestype= $c->salestype;
$type=$c->type;


?>

              
<?php
	
		$totalcash=$totalcash+$c->cash;
		$totalmpesa=$totalmpesa+$c->mpesa;
		
		$totalcredit=$totalcredit+$c->credit;		  
$totalcheque=$totalcheque+$c->cheque;	
$totalvoucher=$totalvoucher+$c->voucher;			  
$totalpoints=$totalpoints+$c->points;	
$totalcard=$totalcard+$c->card;	
		
		
		
		
		$mytax=$this->usermodel->populateall('sales_order','invoice', $myinvoice);
				$cashmpesa=	 $totalmpesa+$totalcash+$totalcredit+$totalcheque+$totalvoucher+$totalpoints+$totalcard;
	
$taxrate=0;

if(is_array($mytax)) {

   foreach($mytax as $myrow){
    $myrow->tax;
$taxrate=$taxrate+$myrow->tax;

}
}
$totaltax= $totaltax+$taxrate;
	}	
		?>
		<tr><td colspan="2"><B><CENTER>PAYMENTS SUMMARY</CENTER> </B></TD></TR>

	<tr><td><B>SALES SUMMARY</B></TD><td><B>SALES</B></TD></TR>
		
							
							<?php if ($totalcash>0)
							{
								
							?>
	
	<tr>
								
								<td ><b>CASH</b></td>
								
								<td colspan="2">
								<?php echo$totalcash?>
								</td>
							
							</tr>
							
							<?php 
							}
								
							?>
							
								<?php if ($totalcard>0)
							{
								
							?>
								<tr>
								
								<td ><b>CARD</b></td>
								
								<td colspan="2">
								<?php echo$totalcard?>
								</td>
							
							</tr>
							
							<?php 
							}
								
							?>
								<?php if ($totalcheque>0)
							{
								
							?>
								<tr>
								
								<td ><b>BANK</b></td>
								
								<td colspan="2">
								<?php echo$totalcheque?>
								</td>
							
							</tr>
							
							<?php 
							}
								
							?>	<?php if ($totalmpesa>0)
							{
								
							?>
								<tr>
								
								<td ><b>MPESA</b></td>
								
								<td colspan="2">
								<?php echo$totalmpesa?>
								</td>
							
							</tr>
							
							<?php 
							}
								
							?>	<?php if ($totalcredit>0)
							{
								
							?>
								<tr>
								
								<td ><b>CREDIT</b></td>
								
								<td colspan="2">
								<?php echo$totalcredit?>
								</td>
							
							</tr>
							
							<?php 
							}
								
							?>	<?php if ($totalvoucher>0)
							{
								
							?>
								<tr>
								
								<td ><b>VOUCHER</b></td>
								
								<td colspan="2">
								<?php echo$totalvoucher?>
								</td>
							
							</tr>
							
							<?php 
							}
								
							?>	<?php if ($totalpoints>0)
							{
								
							?>
								<tr>
								
								<td ><b>L POINTS</b></td>
								
								<td colspan="2">
								<?php echo$totalpoints?>
								</td>
							
							</tr>
							
							<?php 
							}
								
							?>
							
		<tr>
								
								<td ><b>GRAND TOTAL </b></td>
								
								<td colspan="2">
		<?php if(isset($total)) {echo formatMoney($total, true);  }?><b></center></td>
								</td>
							
							</tr>
							
			<table border="1"  width="100%">			

				<tr><td colspan="2"><B><CENTER>DEPARTMENTAL SALES</CENTER> </B></TD></TR>
		
		<?php
		 if(is_array($oursales)) {



  	foreach ($oursales as $row){
		?>
		<tr>
	<td><?php  $maincategoryid= $row->maincategory ; ?>
	
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('maincategory','id',$maincategoryid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No Department.';
}
	
?>
	
	
	
	
	
	
	
	
	</td>
		<td><?php echo $row->cash ; ?></td>
		</tr>
<?php
		
	}
	
	}
		
		?>

		
		
		
				<tr><td colspan="2"><B><CENTER>PRODUCT CATEGORY SALES</CENTER> </B></TD></TR>
		
		<?php
		 if(is_array($sales)) {



  	foreach ($sales as $salesrow){
		?>
		<tr>
	<td><?php  $categoryid= $salesrow->category ; ?>
	
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('productcategory','id',$categoryid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $subcategoryrow){

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



	<?php

}} else {
    echo 'No Sub Category.';
}
	
?>
	
	
	
	
	
	
	
	
	</td>
		<td><?php echo $row->cash ; ?></td>
		</tr>
<?php
		
	}
	
	}
		
		?>
		
		
		
		
		
		
		
		
		
		
		

	
			<tr><td colspan="2"><B><CENTER>TAX SUMMARY</CENTER> </B></TD></TR>

				<tr><td ><b>TAX </b></td><td>  <b><?php if(isset($totaltax)) {echo formatMoney($totaltax, true);  }?><b></td></tr>

	
	
              <?php }?>

        </table>

		
		<br>
		
		
		
		
		
	
		
		
		
		
		
		
		
		
		
		
		</br>
		
				<table border="1"  width="100%">			

             <thead>
			   <tr>
			        <th colspan="6"><CENTER>DAILY EXPENDITURE</CENTER></th>
			     </tr>
         <tr>
    
     <th>Date</th>
		   <th>Description</th>

	 <th>Amount</th>
		     
		
		

                 </tr>
             </thead>
<?php
 
 if(!is_array($viewexpenses)) 

 {


   
    }else {
?>
    
             <?php 
  $totalamount=0;
  	foreach ($viewexpenses as $c): 

		 

             ?>



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

$totalamount=$totalamount+$c->amount ;

?>

              

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

	   <td><?php echo $c->controller ; ?></td>
	  
  <td><?php echo $c->amount ; ?></td>
	
             </tr>

	<?php endforeach; ?>

	
									<tr border="1" background="green">
									<td colspan="1"><b>Total Expenditure</b></td>
		<td colspan="6">
<b><?php if(isset($totalamount)) {echo $totalamount;   }?></b>		</td>

			
									
</tr>
	
									<tr border="1" background="green">
									<?php if(isset($total)) {$finalbalance=$total+$totalamount;  }
									
									?>
									<td colspan="1"><b>Total Money Rendered</b></td>
		<td colspan="6">
<b><?php if(isset($finalbalance)) {echo $finalbalance;   }?></b>		</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="table" value="sales">

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


















