
<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%" id="sortable_table">			

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

			 <B>CATEGORY REPORT(DAILY SALES) <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; }?>
			 								<br>Name----------------------Date--------------------Signature----------------</span>

			 </center>
			 <tr>
       
             </thead>
		
		
		
		
				<tr><td colspan="1"><B><CENTER>PRODUCT CATEGORY SALES</CENTER> </B></TD>
				<td>sales</td>
				<td>Buying Price</td>
				<td>Profit</td>
				
				
				</TR>
		
		<?php
		 if(is_array($sales)) {
$totalsalctegory=0;
$totalprofits=0;
$totalbrice=0;
 $totaltax=0; 
		  		  $totaltaxlevy=0; 

  	foreach ($sales as $salesrow){
		?>
		<tr>
	<td><?php  $categoryid= $salesrow->category ; ?>
	
	<?php 
$profit=0;
			$totaltax=$totaltax+$salesrow->tax ;
$totaltaxlevy=$totaltaxlevy+$salesrow->tax2 ;
$category = $this->usermodel->populateallarray('productcategory','id', $categoryid);

	  $categoryname=$category[0]['name'];
							
$mybranchid=$mybranchid;
?>

<a  id="non-printable" target="_blank"  href="<?php echo base_url();?>user/getsalesbycategory?branchid=<?php   if(isset($mybranchid)) {echo $mybranchid; } ?>&category=<?php   {echo  $categoryid;}  ?>&fromdate=<?php   {echo  $finalfromdate;}  ?>&todate=<?php   {echo  $finaltodate;}  ?>&group=<?php   {echo  $group;}  ?>"><?php  echo $categoryname=$category[0]['name'];?>   </a>
 
 <span id="myprint"><?php echo $categoryname ; ?></span>
	
	
	
	
	
	
	
	
	</td>
		<td><?php  echo formatMoney($salesrow->myamount, true); 
					$totalsalctegory=$totalsalctegory+$salesrow->myamount;

		
		?></td>
		
		<td><?php  echo formatMoney($salesrow->mybprice, true); 
					$totalbrice=$totalbrice+$salesrow->mybprice;

		
		?></td>
		<td><?php  
		$profit=$totalsalctegory-$totalbrice;
				$profit2=$salesrow->myamount-$salesrow->mybprice;

		echo formatMoney($profit2, true); 
					$totalprofits=$totalprofits+$profit;
if($totalbrice>0){
		$percentage=(($profit/$totalbrice)*100);
		
		echo "        Profit".	formatMoney($percentage, true)."%";
}else{
echo " Profit 100%";	
	
}
		?></td>
		</tr>
<?php
		
	}
	?>
	<tr><td><B><CENTER>GRAND TOTAL </CENTER> </B></TD>
	<td>
	<b>
				<?php  echo formatMoney($totalsalctegory, true); 
				?>
		</b>
</td>
	<td>
	<b>
				<?php  echo formatMoney($totalbrice, true); 
				?>
		</b>
</td>
	<td>
	<b>
				<?php  echo formatMoney($profit, true); 
				?>
		</b>
</td>
				</TR>
	<?PHP
	}
		
		?>
			
		
		
		
		
		
		
		
		
		

	
			<tr><td colspan="4"><B><CENTER>TAXES SUMMERY</CENTER> </B></TD></TR>

				<tr><td colspan="2"><b>TAX </b></td><td>  <b><?php if(isset($totaltax)) {echo formatMoney($totaltax, true);  }?><b></td></tr>
				<tr><td colspan="2"><b>LEVY </b></td><td>  <b><?php if(isset($totaltaxlevy)) {echo formatMoney($totaltaxlevy, true);  }?><b></td></tr>

	
	
             

        </table>

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


















