
<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">
<?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;
					}
					  
	function MyformatMoney($number, $fractional=false) {
						if ($fractional) {
							$number = sprintf('%.2f', $number);
						}
						while (true) {
							$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1$1', $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);
  	   $dontshowprofit=$this->usermodel->populatuserpermissionsdataarray('reports','dontshowprofit',$userid);

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

				echo $this->session->flashdata('msg'); 
								?>	
  
		<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>
						
						
										
						
								<?php	
		  $data['category'] = $session_data['category'];
	 $category = $data['category'];
	 	 if($category=="reseller"){
			 ?>
						                        <a  id="non-printable"  class="btn btn-primary" href="<?php echo base_url();?>user/payments">back  </a>

<?php
		 }else{
			?> 
			 
			                        <a  id="non-printable"  class="btn btn-primary" href="<?php echo base_url();?>user/startsales">back  </a>
 
			<?php 
		 }
		 ?>
						
				
				 		 	<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" >				
				
					<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 colspan="22"><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> 
			 FROM  <?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> RCT</th>
									<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>TT. B </th>
												<th>TT. S </th>

												<th> Profit </th>
																								<th>Profit:% </th>

													   
													<th> 	Tax</th>
										<th> Ship/	Tax2</th>
													 <th> S/N</th>  

													 <th> Type</th>  
									       <th>Date sold</th>
										 
									 													<th> Customer</th> 

												<th> Counter</th> 
										    <th> Returned by</th> 
										    <th> Sold by</th>  
											
											  <th> Agent</th>
		   <th id="non-printable"> More</th> 


                 </tr>
             </thead>
<?php



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

  		  $totalbb=0; 
  		  $totalsprice=0; 					
		  
		  		    		  $totalwhprice=0; 					


    $totalqty=0; 
							$totalprofit=0; 
														$ttprofitpercent=0; 

  	foreach ($salesreport as $c): 

	
	
	 $mytax2=$c->mytax2;
  $totaltax2= $totaltax2+ (double)$mytax2;
	
	
	
		 $bprice=$c->bprice;
		 $sprices=0;
		 		 $address=0;

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


	 $address=$c->address ;






		if($group!="yes"){
		$profit=($sprice-$bprice)*$c->myqty;
							$myprofit=($sprice-$bprice)*$c->myqty;		


		if(($bprice==0)|| ($c->qty==0)){
																$ttprofitpercent=(($myprofit/1)*100*$c->qty); 

							}else{
																$ttprofitpercent=(($myprofit)/($bprice*$c->qty)*100); 

							}							
			}else{
					$profit=($c->myamount-($bprice*$c->myqty));
							$myprofit=($c->myamount-($bprice*$c->myqty));
							
							
		if(($bprice==0)|| ($c->qty==0)){
																$ttprofitpercent=(($myprofit/1)*100*$c->myqty); 

							}else{
																$ttprofitpercent=(($myprofit)/($bprice*$c->myqty)*100); 

							}
	
				
				
			}
					
							$profit=(double)$profit-(double)$address;
					

							 $totalprofit=$totalprofit+$profit;


             ?>



             <tr>
                
            <?php 
			$myinvoice=$c->invoice;
	  	 $recipt = $this->usermodel->populateallarray('sales','invoice',$myinvoice);
		 	  $receiptno=$recipt[0]['id'];	
$id=$c->id;
 $salestype =$c->salestype ;
 $totalqty= $totalqty+$c->myqty;
$mycode="";
$tax=$c->mytax;
 $totaltax= $totaltax+ $tax;
$mycode=$c->code;
$myproducts=$this->usermodel->geteproductbyid($mycode);
//echo $receiptno ;
?>

              

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

	echo $c->code  ;



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

	echo $c->code  ;



  ?>
						 </span>
  
  </td>
			
		
  
  
  
  
  
  
  
  
  </td>
  
  
  
  
  
  
  
  
  
  
  

  <td><?php echo $myproducts[0]['name'];



if($myproducts[0]['description'] !=""){
	
	echo "-".$myproducts[0]['description'] ;

}



  ?></td>
    <td><?php  echo $c->salestype; 
	
	; ?></td>
   <td><?php  echo formatMoney($c->bprice, true) ; ?></td>
	  <td><?php 
	

		  $sprices= $c->sprice ; 
	 echo formatMoney($sprices, true) ;
	  ?></td>
	  	 

	  <td><?php echo $c->myqty ; ?></td>
<td><?php	 echo formatMoney($c->discount , true) ;
 ?></td>
  <td><?php 
  $TTB=$c->bprice* $c->myqty ;

   echo formatMoney($TTB , true) ;
  $totalbb=$totalbb+$TTB;
  
  ?></td>

  <td><?php  

		



		if($group!="yes"){
			  $ttprice=$c->sprice* $c->myqty ;
					$total=$total+$ttprice;	
echo formatMoney($ttprice, true) ;					
			}else{
			
				 echo formatMoney($c->myamount , true) ;
				
					  $total=$total+$c->myamount;
	
				
				
			}
										
									

		
	
	


  ?></td>
  
  
      <td >
	  
	  	<?php
		
		
									 if( $dontshowprofit!=true){
											
									
			   echo formatMoney($profit,true);  
	  
									 }
	  ?>
	  
	  
	  
	  </td> 
	    <td ><?php 
		
			 if( $dontshowprofit!=true){
											
									
		echo sprintf('%0.2f', $ttprofitpercent)." %:";
	  
									 }
		
		
		
	  
	  
	  ?></td> 
           
			       <td><?php
								   echo formatMoney($c->mytax,true);  

				   ?></td>
				   			       <td><?php 
								      

								   if($c->address !=""){
	
	echo $c->address ;

}
								   
								   if($c->mytax2 !=""){
	

	 echo formatMoney($c->mytax2,true);

}
								 
								   ?></td>
														    <td><?php echo $c->serial ; ?></td>

				    <td><?php echo $c->status ;
if($c->description !=""){
	
	echo "<br>".$c->description ;

}


					?></td>

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

  $allsales = $this->usermodel->getsalesbyinvoice($c->invoice);
						 $mycustomer=$allsales[0]['customer'];
						  $salesperson=$allsales[0]['salesperson'];
						  $ourname=$allsales[0]['name'];
						  $description=$allsales[0]['description'];



  //$mycustomer= $c->customer ;
  
    if(($mycustomer!="") && ($mycustomer!="directly")){

$myuser=$this->usermodel->getpeople($mycustomer);
    $myname=$myuser[0]['company'];
	    $phone=$myuser[0]['phone'];

     $firstname=$myuser[0]['firstname'];
   if($myname!=""){
	   echo $myname."-".$phone;
	   
   }else{
	   
	   echo $firstname."-".$phone; 
	   
   }
	}else{
		echo $name= $ourname;
		
	}
	echo " ".$description ;
  ?>
 
 
 </td>
  
  
  
  
  
	 <td>
												 
	<?php 
					// $branch="";
					 $branch=$c->branch;

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



if(is_array($branch)) {

   foreach($branch as $branchrow){

   echo $branchrow->name;
 
 
}} else {
    echo 'General.';
}
	
?>
												 
	 </td>
 <td><?php 
if($user=="all"){
	echo "Everyone";
}else{
	


 $userids= $c->updatedby ;

$myuser=$this->usermodel->geteuser($userids);
   echo $myname=$myuser[0]['firstname'];
}
  ?></td> 
  
  
   <td><?php 
if($user=="all"){
	echo "Everyone";
}else{
	


 $userid= $c->userid ;

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

 
	 <td><?php  

$mycustomer=$this->usermodel->populateallarray('people','id', $salesperson);


			
			if($salesperson !=""){
				if($mycustomer[0]['company']!=""){
									echo$myname=$mycustomer[0]['company'];

				}else{
									echo$myname=$mycustomer[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">
                                        More <span class="caret"></span>
                                    </button>
								
                                    <ul class="dropdown-menu dropdown-primary pull-right" role="menu">
                                        
                                        <!--
                                      
											<?php
									 if( $deleteaction==true){
											
											?>
											  <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>
										<?php
										}
										?>
									
							-->
									  <li class="divider"></li>
                                        
														<li> 
										
										
									
								
										
										
										
											 	 <a  id="more"  target="_blank"  class="btn btn-default" href="<?php echo base_url();?>user/searchallmyinvoices?searchterm=<?php   {echo  $myinvoice;}  ?>&page=<?php   {echo  0;}  ?>&view=userdata/allinvoices">View whole receipt  </a>

                                                        </li>    
                                        <li class="divider"></li>
                                        
														<li> 
										
											 	 <a  id="more" target="_blank" class="btn btn-default" href="<?php echo base_url();?>user/viewprice?randomitemidentifier=<?php   {echo  $mycode;}  ?>&view=user/viewsales">Production  </a>

                                                        </li>                                        
                                    </ul>
										
                                </div>
</td> 
         
             </tr>

	<?php endforeach; ?>

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

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

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

		 if( $dontshowprofit!=true){
											
									
	if(isset($totalprofit)) {echo formatMoney($totalprofit, true);  }	  
									 }




								
									
									?> </b> </td>

</td>
<td></td>
<td><b><?php if(isset($totaltax)) {echo formatMoney($totaltax);  }?> </b></td>
<td><b><?php if(isset($totaltax2)) {echo formatMoney($totaltax2);  }?> </b></td>


<td colspan="3"><b>TT service Charge:<?php 

		$configuration= $this->usermodel->populateallarray('smsconfig','id',$companyid);

	$display3=$configuration[0]['displayservicecharge'];
	 $servicecharge=$configuration[0]['servicecharge'];
	 if($display3=="yes"){
$ttservicecharge=(($servicecharge/100)*$total);


if(isset($ttservicecharge)) {echo formatMoney($ttservicecharge);  }


	 }

?> </b></td>

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


















