
<script>

    function selectAllCheckBoxes(obj){
        $('input:checkbox:not(:disabled).checkBoxInLoop').prop('checked', jQuery(obj).prop('checked'));
    }

    function unselectCheckBoxUnik(){

        /*first you verify if the quantity of checkboxes equals number of checkboxes*/
        a = $('input:checkbox:not(:disabled).checkBoxInLoop:checked').size();
        b = $('input:checkbox:not(:disabled).checkBoxInLoop').size();

        /*if equals, mark a checkBoxUnik*/
        ((a == b)? $('#checkBoxUnik').prop("checked", true) : $('#checkBoxUnik').prop("checked", false));
    }

		
		
		
	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">
	<?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;
					}
					 $finalstartdate=date("Y-m-d 00:00:00");
					  $finalendate=date("Y-m-d H:i:s");

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'];	
	 
	 
	 	 $smsconfig = $this->usermodel->populateallarray('smsconfig','id',$companyid);
		 		$currenttime = date('H:i');

		 
  	$dateString = '2020-02-05';
 
//Last date of current month.
//echo$lastDateOfMonth = date("Y-m-t", strtotime($dateString));
		  $year=date("Y");
		  $month=date("m");
		   $day=date("d");
		   
		   
		   $subtract=$day-1;
		   $add=$day+1;
		      if ($subtract<10){
			  $subtract="0".$subtract;
		   }else{
			   $subtract=$subtract; 
		   }
		$finalstartdate="";
		$finalendate="";
		  $myfromdate=$smsconfig[0]['fromdate'];
		 $mytodate=$smsconfig[0]['todate'];
		 $starttime=$smsconfig[0]['starttime'];
		 $duetime=$smsconfig[0]['duetime'];
		
	if(($myfromdate=="Current") &&($mytodate=="Current") &&  ($currenttime>=$starttime)){
	
		  $finalstartdate=$year.'-'.$month.'-'.$day.' '. $starttime.':00';
		
		 }else if(($myfromdate=="Current") &&($mytodate=="Next") &&  ($currenttime>=$starttime)){
	
		  $finalstartdate=$year.'-'.$month.'-'.$day.' '. $starttime.':00';
		
		 }
		 
		  else if(($myfromdate=="Current") &&($mytodate=="Current") && ($currenttime<$starttime)){
					  $finalstartdate=$year.'-'.$month.'-'.$day.' '. $starttime.':00';


				
		 }
		 
		 else if(($myfromdate=="Current") &&($mytodate=="Next") && ($currenttime<$starttime)){
			 if(($day=="01") || ($day=="1")){
				 
				 $currentdate=$year.'-'.$month.'-'.$day;

 $mynewfromdate = strtotime ( '-1 month' , strtotime ( $currentdate ) ) ;
$newfromdate = date ( 'Y-m-d' , $mynewfromdate );
$finalstartdate = date("Y-m-t", strtotime($newfromdate)).' '.$starttime.':00';
			 }else{
			
								  $finalstartdate=$year.'-'.$month.'-'.$subtract.' '. $starttime.':00';

			
			 }
	


		 }

	
					

		
		 
		 
		if(($mytodate=="Next") && ($currenttime>=$duetime)){
	
		  $finalendate=$year.'-'.$month.'-'.$add.' '. $duetime.':00';
				//echo $finalstartdate;
		
		 }else if(($mytodate=="Next") && ($currenttime<$duetime)){
			
		  $finalendate=$year.'-'.$month.'-'.$day.' '. $duetime.':00';
		  
				//	echo $finalstartdate;
		 }else  if(($mytodate=="Current") && ($currenttime>=$duetime)){
		 		  $finalendate=$year.'-'.$month.'-'.$add.' '. $duetime.':00';

		 }else  if(($mytodate=="Current") && ($currenttime<$duetime)){
					  $finalendate=$year.'-'.$month.'-'.$day.' '. $duetime.':00';

		  
				//	echo $finalstartdate;
		 }
		 
		 
		 
		 
		 
		 
		 
		 
		 
	 
	    $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);
	 	   		 						$updatepaymentmode=$this->usermodel->populatuserpermissionsdataarray('sales','updatepaymentmode',$userid);

			    $cashiersales=$this->usermodel->populatuserpermissionsdataarray('cashiersales','all',$userid);
			    $cashierreprint=$this->usermodel->populatuserpermissionsdataarray('sales','reprint',$userid);
			    $pendingmpesareports=$this->usermodel->populatuserpermissionsdataarray('cashiersales','mpesapendingreport',$userid);
				
					      $mergebill=$this->usermodel->populatuserpermissionsdataarray('sales','mergebill',$userid);

	   $viewallaction=$this->usermodel->populatuserpermissionsdataarray('reports','viewall',$userid);
	   
	   		  		  	      $advanceaction=$this->usermodel->populatuserpermissionsdataarray('sales','advance',$userid);

	   	   $viewdailycollections=$this->usermodel->populatuserpermissionsdataarray('cashiersales','viewdailycollections',$userid);

		   	   $adddailycollection=$this->usermodel->populatuserpermissionsdataarray('cashiersales','adddailycollection',$userid);
		   	   $clearallsales=$this->usermodel->populatuserpermissionsdataarray('cashiersales','clearallsales',$userid);
$mpesaaction=$this->usermodel->populatuserpermissionsdataarray('sales','mpesa',$userid);
	      $chequeaction=$this->usermodel->populatuserpermissionsdataarray('sales','cheque',$userid);
 $voucheraction=$this->usermodel->populatuserpermissionsdataarray('sales','voucher',$userid);
	      $creditaction=$this->usermodel->populatuserpermissionsdataarray('sales','credit',$userid);
		   $pointsaction=$this->usermodel->populatuserpermissionsdataarray('sales','points',$userid);
	      $cardaction=$this->usermodel->populatuserpermissionsdataarray('sales','card',$userid);
	      	$pendingisdefault =$this->usermodel->populatuserpermissionsdataarray('cashiersales','pendingisdefault ',$userid);
 	   $clearsalesisdefault =$this->usermodel->populatuserpermissionsdataarray('cashiersales','clearsalesisdefault ',$userid);


				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>
					<?php	
	if(( $pendingisdefault==true)||( $clearsalesisdefault==true)) {
		  
			  
		  }else{
			?>
			<a href="<?php echo base_url();?>user/mysales" class="btn btn-info">  Go back to Cashier sales  </a>	

			<?php
		  }	 
								 
			?>
					<a href="<?php echo base_url();?>user/viewsales" class="btn btn-primary">  Go back to sales window  </a>	

 <?php 
				 	 if( $mergebill==true){
										 ?>
								 <a href="<?php echo base_url();?>user/mergebill" class="btn btn-info"> View all merged bills</a>	
									
																	 <a href="<?php echo base_url();?>user/splitbill" class="btn btn-info"> View all splitted bills</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" id="non-printable">
        <?php 
		
        $attr = array("class" => "form-horizontal", "role" => "form", "id" => "search", "name" => "search");
        echo form_open("user/searchforinvoice", $attr);?>
            <div class="form-group">
			
                <div class="col-md-5">
                    <input class="form-control" id="code" name="code" placeholder="Search for sales  by Receipt No or Refrenece No" type="text" value="<?php echo set_value('searchterm'); ?>" />
                </div>
								<input type="hidden" name="view" value="user/clearsales" id="view" class="form-control" required placeholder="Enter view">

                <div class="col-md-4">
                    <input id="btn_search" name="btn_search" type="submit" class="btn btn-success" value="Search" />
                    <a href="<?php echo base_url(). "user/clearsales"; ?>" class="btn btn-primary">Refresh</a>
                </div>
				 
            </div>
        <?php echo form_close(); ?>

        </div>
						<div class="col-md-12">
							
							<div class="panel-body">
	<?php
			
			 	$myinvoice = $userid.time();

                 echo form_open('user/groupbycategory' , 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" name="myview" value="user/mergebill" id="view" class="form-control" required placeholder="Enter view">

													<input type="hidden" name="view" value="user/clearsales" id="view" class="form-control" required placeholder="Enter view">
																

																<input type="hidden" name="myinvoice" value="<?php echo $myinvoice; ?>"  class="form-control" required placeholder="Enter view">

				<table border="1"  width="100%" id="sortable_table">			

             <thead>
			 		 
         <tr>
		 
		 <th colspan="14"> SELECT MANY RECEIPT FOR BULK UPDATE(CLEARANCE/MERGING)</th>
		<th colspan="2"> 
		 <?php 
				 	 if( $mergebill==true){
										 ?>
			         <button type="submit"  value="merge" name="mergebill" class="btn btn-primary"> Merge Bill  </button>
									<?php
									 }
									 ?>
									 
									 				 <?php 
				 	 if( $clearallsales==true){
										 ?>
	
								<?php
									 }
									 ?>
						
			         <button type="submit"  value="Ready" name="groupbycategory" class="btn btn-info"> Ready  </button>
			         <button type="submit"  value="Served" name="groupbycategory" class="btn btn-info"> Served  </button>


</th>
<th></th>
									<th colspan="2">
	
	<select name="type" id="type" class="form-control1"  style="width:60%">

	<option value="" selected="selected">-SELECT-</option>


	<option value="Cash" >Cash</option>

	









<?php
 if( $mpesaaction==true){
	 ?>
<option value="Mpesa">Mpesa</option>
		<?php	
		}
  ?>


<?php
 if( $cardaction==true){
	 ?>
<option value="Card">Card</option>
		<?php	
		}
  ?>
  
  
  
<?php
 if( $creditaction==true){
	 ?>
<option value="Invoice">Invoice / Credit</option>
		<?php	
		}
  ?>
  
  

  
<?php
 if( $chequeaction==true){
	 ?>
<option value="Cheque">Bank</option>
		<?php	
		}
  ?>
  
<?php
 if( $advanceaction==true){
	 ?>
<option value="Advance"  >Advance</option>
		<?php	
		}
  ?>

  
  <?php
  //
 if( $voucheraction==true){
	 ?>
<option value="Voucher">Voucher/Complimentary</option>
		<?php	
		}
  ?>
  
  
<?php
 if( $pointsaction==true){
	 ?>
<option value="Points">Bonga Points</option>
		<?php	
		}
  ?>
  
  
  
<?php
 if( $creditnoteeaction==true){
	 ?>
<option value="Creditnote">Credit Note</option>
		<?php	
		}
  ?>


</select>										



									
									
									 <?php 
				 	 if( $clearallsales==true){
										 ?>
				
<select class="form-control" name="categoryid" >
	


	
	
										<option value="">--Select status--</option>
			                         <option selected="selected" value="Cleared">Cleared</option>
									 																 <option value="No">No(Not cleared)</option>
									   <option value="Served">Served</option>

									   <option value="Pending">Pending</option>

								

							
</select>									<?php
									 }
									 ?>
									
					
</th>

<th colspan="2"> 
								 <?php 
				 	 if( $clearallsales==true){
										 ?>
			         <button type="submit"  value="all" name="groupbycategory" class="btn btn-info"> Update All  </button>
										         <button type="submit"  value="print" name="groupbycategory" class="btn btn-warning"> Update & Print  </button>
	
								<?php
									 }
									 ?>


</th>  


					 
         </tr> 
			 
         <tr>
		 
		       
    	 <th> <input type="checkbox" onclick="selectAllCheckBoxes(this)" id="checkBoxUnik"/>All
</th>
	
									<th id="non-printable"> Actions</th>
										 	<th> RCT No</th>
                                        <th>  Mode</th>
										   

                                              <th> Table</th> 
														<th> Total</th> 
                                              <th> Bal</th>   
											  <th> Cash</th>  
											 <th> Mpesa</th>
												<th> Card</th>  
											 <th> Voucher</th> 
												<th> Credit</th> 											
											  <th> Points</th>                       
											  <th>Cheque</th> 
											  
		<?php
 if( $advanceaction==true){
	 ?>
											  	  <th>Advance</th> 


	 
	  <?php
}
?>

	

												<th> Code</th>											  
											                      
											  <th>Customer</th>                            

											
											 

									       <th>Date sold</th>
										 
									
											<th> Counter</th> 

										    <th> sold by</th>  
							 <th> Room</th>  

											<th> Status</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; 
    $totalcash=0; 
		  $totaltax=0; 
$totalmpesa=0;		  
$cashmpesa=0;

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



  	foreach ($salesreport as $c): 
$totalcash=(double)$totalcash+(double)$c->cash;
		$totalmpesa=(double)$totalmpesa+(double)$c->mpesa;
		$totaladvance=(double)$totaladvance+(double)$c->advance;	

		$totalcredit=(double)$totalcredit+(double)$c->credit;		  
$totalcheque=(double)$totalcheque+(double)$c->cheque;	
$totalvoucher=(double)$totalvoucher+(double)$c->voucher;			  
$totalpoints=(double)$totalpoints+(double)$c->points;	
$totalcard=(double)$totalcard+(double)$c->card;	
$cashmpesa=	 (double)$totalmpesa+(double)$totalcash+(double)$totalcredit+(double)$totalcheque+(double)$totalvoucher+(double)$totalpoints+(double)$totalcard+(double)$totaladvance;
	$mytotal=(double)$totalmpesa+(double)$totalcash+(double)$totalcheque+(double)$totalpoints+(double)$totalcard;
 $myinvoice=$c->invoice ; 
 
 
           
          
$id=$c->id;
 $total=(double)$total+(double)$c->total;


 $view="";
$salestype= $c->salestype;
$type=$c->type;
if ($salestype=="wholesale"){
		
	  $view="user/viewwholesales";
}else if ($salestype=="retail"){

	 $view="user/viewsales";

}else{
	 $view="user/viewsales";
	
}
 
?>




             <tr>
			 <td>
			<input name="selector[]" type="checkbox" onclick="unselectCheckBoxUnik()" class="checkBoxInLoop" value="<?php echo $c->id ; ?>">
				</td>
  
              
  <td id="non-printable">
  
    
  <?php	
								
	 if($updatepaymentmode==true){
		 
		  if($c->paymentstatus !="Cleared"){
		 //
								?>
						<a  id="more" class="btn btn-info" href="<?php echo base_url();?>user/changepayment?invoice=<?php   if(isset($myinvoice)) {echo $myinvoice; } ?>"> Clear   </a>

									 	<?php	
										
		  }

 }else{
	
 }
 										
?>
	
  
  <?php
  		if($type=="Invoice"){
											
 if( $cashierreprint==true){
										 ?>
				 <a  id="non-printable" target="_blank"  href="<?php echo base_url();?>user/printinvoice?invoice=<?php   if(isset($myinvoice)) {echo $myinvoice; } ?>&view=<?php   {echo  $view;}  ?>"> -Print   </a>
						 <span id="myprint"><?php echo $c->invoice ; ?></span>

									<?php
									 }else{
										 
										 if(isset($myinvoice)) {echo $myinvoice; } 
										 
										 
									 }			
									 ?>
												
		

								<?php
								}else{
									 if( $cashierreprint==true){
									?>
				
				 <a  id="non-printable" target="_blank"  href="<?php echo base_url();?>user/printreceipts?invoice=<?php   if(isset($myinvoice)) {echo $myinvoice; } ?>&view=<?php   {echo  $view;}  ?>"> Print   </a>
						 <span id="myprint"><?php echo $c->invoice ; ?></span>

									<?php
									 }else{
										 
										 if(isset($myinvoice)) {echo $myinvoice; } 
										 
										 
									 }			
									 ?>
								
								
								
								
								
								
								
								
								
								
								<?php
								}
								?>

  
  			    <a id="non-printable" class=" btn-primary" href="<?php echo base_url();?>user/printdelivery?invoice=<?php   if(isset($myinvoice)) {echo $myinvoice; } ?>">Delivery   </a>

  </td>
       



 
 <?php
 if($c->ordersales=="Served"){
	 ?> 
	     <td style="background:green"><?php echo $c->id; ?></td>

	 <?php
 }else{
	 ?> 
	     <td><?php echo $c->id; ?></td>

	 <?php 
 
 }
 ?>

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

  	  <td>
	   <a  id="non-printable" class="btn btn-warning"  href="<?php echo base_url();?>user/searchinvoice?code=<?php   if(isset($myinvoice)) {echo $myinvoice; } ?>&view=<?php   {echo  $view;}  ?>"> <?php if($c->mytable){echo $c->mytable;}else{ echo "view";} ?>   </a>
 			<input name="mytable[]" type="hidden" value="<?php echo $c->mytable ; ?>">
 			<input name="invoice[]" type="hidden" value="<?php echo $myinvoice ; ?>">

	  
	  </td>
 <td>
 <a  id="non-printable"  href="<?php echo base_url();?>user/searchinvoice?code=<?php   if(isset($myinvoice)) {echo $myinvoice; } ?>&view=<?php   {echo  $view;}  ?>"> <?php echo $c->total ; ?>   </a>
 
 <span id="myprint"><?php echo $c->total ; ?></span>

 </td>
    <td><?php echo $c->balance ; ?>
	 			<input name="finaltotal[]" type="hidden" value="<?php echo $c->total ; ?>">

	
	</td>
   <td><?php echo $c->cash ; ?></td>
      <td><?php echo $c->mpesa ; ?></td>
			     <td><?php echo $c->card ; ?></td>
											   <td><?php echo $c->voucher ; ?></td>
												  <td><?php echo $c->credit ; ?></td>
												   <td><?php echo $c->points ; ?></td>
											   <td><?php echo $c->cheque ; ?></td>
											    <td><?php echo $c->cashier ; ?></td>

	 
		<?php
 if( $advanceaction==true){
	 ?>
   <td><?php echo $c->advance ; ?></td>

	 
	  <?php
}
?>

	

	 

<td><?php  $customer=$c->customer ;

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


			echo$myname=$mycustomer[0]['firstname']. $customer=$c->name;

 ?></td>

 <td><?php echo $c->dateposted	 ; ?></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  $userids= $c->userid ;

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

  ?></td>  
  <td><?php 
if($c->houseno !=""){
	echo $c->houseno."-".$c->plotno ;
}else{
}



 ?></td>
 
 <?php
 if($c->ordersales=="Served"){
	 ?> 
	     <td style="background:green"><?php echo $c->paymentstatus ."-".$c->ordersales; ?></td>

	 <?php
 }else{
	 ?> 
	     <td><?php echo $c->paymentstatus ."-".$c->ordersales; ?></td>

	 <?php 
 
 }
 ?>
   		 
		 	<?php echo form_close();?>
         
             </tr>

	<?php endforeach;} ?>

								<tr border="1" background="green">
									<td colspan="6"><center><b>Expected  Amount:
		<?php if(isset($total)) {echo formatMoney($total, true);  }?><b></center></td>

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

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

			<td>  <b><?php if(isset($totalvoucher)) {echo formatMoney($totalvoucher, true);  }?><b></td>
	<td>  <b><?php if(isset($totalcredit)) {echo formatMoney($totalcredit, true);  }?><b></td>
				<td>  <b><?php if(isset($totalpoints)) {echo formatMoney($totalpoints, true);  }?><b></td>
			<td>  <b><?php if(isset($totalcheque)) {echo formatMoney($totalcheque, true);  }?><b></td>
			<td>  <b><?php if(isset($totaladvance)) {echo formatMoney($totaladvance, true);  }?><b></td>

			<td colspan="2"></td>

		
			<td colspan="6">  <b>Total for all payments : <?php if(isset($cashmpesa)) {echo formatMoney($cashmpesa, true);  }?><b></td>
	<td id="non-printable"></td>
</tr>
	
	
	
              <?php }?>

        </table>
		
	 <div class="col-md-12 text-center">    <?php echo $links; ?>
					   		<span style="color:red; font-size:20px"><?php  echo $total_rows. "   Sales. " ;?>    </span>

        
        </div>
		
		
	</div>
	
		<div id="usersummaryModal" 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">Sales Summary Report per user</h4>
      </div>
      <div class="modal-body">
      


				<?PHP
//$session_data = $this->session->userdata('logged_in');



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/viewgsummaryreportbyuser' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>

		  			  		<input type="hidden" name="type" value="all" class="form-control"  placeholder="Enter type">

  <div class="form-group">
    <label for="inputbranchname" class="col-sm-2 control-label">Counter</label>
    <div class="col-sm-10">
	<select class="form-control" name="branchname"  id="branchname" required>
	
	
	<option value=""  >---Select Branch/Counter Name--</option>
<?php
									 if( $viewallaction==true){
										 ?>
					<option value="all"  >All branches/Counters</option>
									<?php
									 }
							
	?>
	
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No main counter available.';
}
	
?>
</select>
		

		
	</div>
  </div>
	
	
				  		<input type="hidden" name="view" value="viewgroupreceiptreport" class="form-control" required placeholder="Enter sales type">

     <div class="form-group">
    <label for="inputuser" class="col-sm-2 control-label">User?</label>
    <div class="col-sm-10">
	<select class="form-control" name="user" required>
	
	<option value=""  >---Select user---</option>

						<?php
		
		 if($cashiersales==true){
			$allusers = $this->usermodel->populatealldatanoarray('people', 'companyid',$companyid,'status',1);
			?>
						<option value="all"  >All 	users</option>
<?php


 }else{
			$allusers = $this->usermodel->populatealldatanoarray('people', 'id',$userid,'status',1);

 
  
 }
  ?>

	
	
	
	<?php 
				
				
	

	
if(is_array($allusers)) {

   foreach($allusers as $userrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $userrow->id;   ?>"><?=  $userrow->email ."(". $userrow->firstname ."- ".$userrow->surname.")"; ?></option>



	<?php

}} else {
    echo 'No user available.';
}
	
?>
</select>
		
						<span class="text-danger"><?php echo form_error('people'); ?>

	</div>
  </div>
  
  
  
  
  
  
  
  
  
	
	
	
	
	
  <div class="form-group">
    <label for="inputfromdate" class="col-sm-2 control-label">From Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="fromdate" value="<?php echo set_value('fromdate',$finalstartdate); ?>" class="form-control" required placeholder="Enter start date">
		 
				
		<span class="text-danger"> <?php echo form_error('fromdate'); ?>
		
		</span>
	</div>
  </div>
  
  	<div class="form-group">
    <label for="inputtodate" class="col-sm-2 control-label">	To Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="todate" value="<?php echo set_value('todate',$finalendate); ?>" class="form-control" required placeholder="Enter End date">
		 
				
		<span class="text-danger"> <?php echo form_error('todate'); ?>
		
		</span>
	</div>
  </div>
  
    
     <div class="form-group">
	 
	 
	 
    <label for="inputdisplay" class="col-sm-2 control-label">Dispaly type?</label>
    <div class="col-sm-10">
	<select class="form-control" name="display" required>
	<option  value="all"  >---Do you want to print user z-report--</option>
	<option value="yes" >Yes</option>
<option selected="selected" value="no">No i want to just view sales</option>

	
</select>
		
						<span class="text-danger"><?php echo form_error('display'); ?>

	</div>
  </div>
   

	 <div class="form-group">
    <label for="inputviewmaincategory" class="col-sm-2 control-label">Department Category?</label>
    <div class="col-sm-10">
	<select class="form-control" name="maincategory"  id="maincategory" required>
	
	<option selected="selected" value="all"  >---All/Any Category--</option>

	
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('maincategory','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No main category available.';
}
	
?>
</select>
		
						<span class="text-danger"><?php echo form_error('maincategory'); ?>

	</div>
  </div>

  

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="event" name="btn_addevent" class="btn btn-primary"> View Sales  </button>

    </div>
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </div>
    </div>

			<div id="userModal" 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">Sales Report per user</h4>
      </div>
      <div class="modal-body">
      


				<?PHP
//$session_data = $this->session->userdata('logged_in');



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/viewgroupreceiptreportbyuser' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>

		  			  		<input type="hidden" name="type" value="all" class="form-control"  placeholder="Enter type">

  <div class="form-group">
    <label for="inputbranchname" class="col-sm-2 control-label">Counter</label>
    <div class="col-sm-10">
	<select class="form-control" name="branchname"  id="branchname" required>
	
	
	<option value=""  >---Select Branch/Counter Name--</option>
<?php
									 if( $viewallaction==true){
										 ?>
					<option value="all"  >All branches/Counters</option>
									<?php
									 }
							
	?>
	
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No main counter available.';
}
	
?>
</select>
		

		
	</div>
  </div>
	
	
				  		<input type="hidden" name="view" value="viewgroupreceiptreport" class="form-control" required placeholder="Enter sales type">

     <div class="form-group">
    <label for="inputuser" class="col-sm-2 control-label">User?</label>
    <div class="col-sm-10">
	<select class="form-control" name="user" required>
	
	<option value=""  >---Select user---</option>

						<?php
	
		
		
		 if($cashiersales==true){
			$allusers = $this->usermodel->populatealldatanoarray('people', 'companyid',$companyid,'status',1);
	?>
		<option value="all"  >-All users-</option>

	<?php

 }else{
			$allusers = $this->usermodel->populatealldatanoarray('people', 'id',$userid,'status',1);

 
  
 }
  ?>

	
	
	
	<?php 
				
				
	

	
if(is_array($allusers)) {

   foreach($allusers as $userrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $userrow->id;   ?>"><?=  $userrow->email ."(". $userrow->firstname ."- ".$userrow->surname.")"; ?></option>



	<?php

}} else {
    echo 'No user available.';
}
	
?>
</select>
		
						<span class="text-danger"><?php echo form_error('people'); ?>

	</div>
  </div>
  
  
  
  
  
  
  
  
  
	
	
	
	
	
  <div class="form-group">
    <label for="inputfromdate" class="col-sm-2 control-label">From Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="fromdate" value="<?php echo set_value('fromdate',$finalstartdate); ?>" class="form-control" required placeholder="Enter start date">
		 
				
		<span class="text-danger"> <?php echo form_error('fromdate'); ?>
		
		</span>
	</div>
  </div>
  
  	<div class="form-group">
    <label for="inputtodate" class="col-sm-2 control-label">	To Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="todate" value="<?php echo set_value('todate',$finalendate); ?>" class="form-control" required placeholder="Enter End date">
		 
				
		<span class="text-danger"> <?php echo form_error('todate'); ?>
		
		</span>
	</div>
  </div>
  
    
     
   

	 <div class="form-group">
    <label for="inputviewmaincategory" class="col-sm-2 control-label">Department Category?</label>
    <div class="col-sm-10">
	<select class="form-control" name="maincategory"  id="maincategory" required>
	
	<option selected="selected" value="all"  >---All/Any Category--</option>

	
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('maincategory','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No main category available.';
}
	
?>
</select>
		
						<span class="text-danger"><?php echo form_error('maincategory'); ?>

	</div>
  </div>

  

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="event" name="btn_addevent" class="btn btn-primary"> View Sales  </button>

    </div>
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

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


















