<?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;
					}


?>


<?PHP

 echo $this->session->flashdata('imagemsg1'); 
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'];	
	 $data['branchid'] = $session_data['branchid'];
	 $branchid = $data['branchid'];
	 
	 
	    $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);
	   $viewallaction=$this->usermodel->populatuserpermissionsdataarray('reports','viewall',$userid);
	   $dontshowprofit=$this->usermodel->populatuserpermissionsdataarray('reports','dontshowprofit',$userid);
 $viewaccounting=$this->usermodel->populatuserpermissionsdataarray('accountingreports','view',$userid);
//viewallaction

   $userid=$data['id'];
 //$finalendate=date("Y-m-d H:59:59");
 // $finalstartdate=date("Y-m-d 00:00:00");
  
  
    $finalstartdate1=date("Y-m-01 00:00:00");

	 	 $smsconfig = $this->usermodel->populateallarray('smsconfig','id',$companyid);
		 		$currenttime = date('H:i');
					$etims=$smsconfig[0]["hscode"];

		 
		  $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'];
		 //echo $myfromdate;
		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';


				//	echo $finalstartdate;
		 }
		 
		 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.'-'.$day.' '. $duetime.':00';

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

		  
				//	echo $finalstartdate;
		 }
		 
		 	 $finalendatechecker = htmlspecialchars(trim(explode('-',date("Y-m-d", strtotime($finalendate)))[0]));	
		
					
		 if($finalendatechecker=="1970"){
			 
			 

		$mynew_date = date("Y-m-d", strtotime("+1 day"));
			 
			 
		 $finalendate=$mynew_date.' '. $duetime.':00';	 
		 }
		
		 
  
  
  
  
  
  
  
  
  
     $mydate=date("Y-m-d");

  
  
   //$finalendate=date("Y-m-d H:i:s");
 
   $myuser=$this->usermodel->geteuser($userid);
   $myname=$myuser[0]['firstname'];

?>










 <div class="row">

    <div class="col-md-12">
		<div class="panel panel-primary" data-collapsed="0">
        	<div class="panel-heading">
            	<div class="panel-title" id="redcolor" >
            		<i class="entypo-plus-circled"></i>
		
				
				<h1> <center> WELCOME TO AGENT /RESELLER DASHBOARD</center>  </H1>
				
				
            	</div>
            </div>
			<div class="panel-body">

			
										
				<div class="container" style="width:100%">
	<div class="row">
	
	



  
	
	
	
     

    	<div class="col-sm-3">
    		<div class="tile-progress tile-green">
    			<div class="tile-header">
    		<h3> Sales Report
			</h3>
				<i class="fa fa-cubes" style="font-size:30px"></i>

    				
					
						<span>
					          <a data-toggle='modal' data-target='#customergroupModal' class="btn btn-success"> Sales Per Customer / Agents/Resellers </a>

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

	
		
		
    </div>
	
	
	
	
	
	
	
				<div id="customergroupModal" 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">Group Sales per customer/Cashier</h4>
      </div>
      <div class="modal-body">
      
	  	

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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/viewproductgroupsalesreportbycustomer' , 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" id="view"name="view" class="view" placeholder="view" value="user/viewgroupsalesreport">

 
  <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
									
							
				 
					 		$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.';
}
 }else{
?>
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('branch','id',$branchid);


							


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>
	 <div class="form-group">
    <label for="inputsearchtype" class="col-sm-2 control-label">Select Report Type</label>
    <div class="col-sm-10">
	<select class="form-control" name="searchtype"  required>
	
	
	<option value=""  >---Search Report Type  </option>

					<option selected="selected"  value="Personnel">By Agents/Resellers</option>
			

</select>
		

		
	</div>
  </div>
  
	
	 <div class="form-group">
    <label for="inputgroup" class="col-sm-2 control-label">Group Items?</label>
    <div class="col-sm-10">
	<select class="form-control" name="group"  required>
	
	
	<option value=""  >---Use Group Items?--</option>

					<option  value="summary">Yes (Total sales only)</option>
									<!--	<option   value="yes">Yes(Receipt Sales summary)</option>

					<option  selected="selected" selected="selected" value="no">No(Everything)</option>
-->
</select>
		

		
	</div>
  </div>
	
		 <div class="form-group">
    <label for="inputactiontype" class="col-sm-2 control-label">Action</label>
    <div class="col-sm-10">
	<select class="form-control" name="actiontype"  required>
	
	
	<option value=""  >---Select action-</option>
					<option  selected="selected" value="View">View sales</option>

					<option  value="print">Print Bulk Invoice</option>

</select>
		

		
	</div>
  </div>
		

	
  
  
   <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



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

  

  ?>

	
	
	
	<?php 
				
				
	

	
if(is_array($allusers)) {

   foreach($allusers as $userrow){

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



	<?php

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

	</div>
  </div>
  
	
	
	
	
						    <label for="inputfromdate" class="col-sm-2 control-label">From Date </label>

				<div class="col-sm-5">
					<div class="form-group">

                     		  		<input type="date" name="fromdate" value="<?php echo set_value('fromdate',date("Y-m-d", strtotime($finalstartdate))); ?>" class="form-control" required placeholder="Enter start date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					

							  		<input type="time"  name="frotime" value="<?php echo set_value('frotime',$starttime.":00"); ?>" class="form-control" required placeholder="Enter start time">

					</div>
				</div>
			

			
			
						    <label for="inputfromdate" class="col-sm-2 control-label">To Date </label>

				<div class="col-sm-5">
					<div class="form-group">

		  		<input type="date" name="todate" value="<?php echo set_value('todate',date("Y-m-d", strtotime($finalendate))); ?>" class="form-control" required placeholder="Enter End date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					

							  		<input type="time"  name="totime" value="<?php echo set_value('totime',$duetime.":00"); ?>" class="form-control" required placeholder="Enter stop time">

					</div>
				</div>
			
  
    

   

	
		 <div class="form-group">
    <label for="inputcommissiontype" class="col-sm-2 control-label">Commission Type?</label>
    <div class="col-sm-10">
	<select class="form-control" name="commissiontype"  required>
	
	
	<option value=""  >---Select Commission type?--</option>

					<option  value="Gross">On Gross</option>
					<option    selected="selected" value="Profit">On Profit</option>

</select>
		

		
	</div>
  </div>
	
	
	
	
		 <div class="form-group">
	 
	 
	 
    <label for="inputtype" class="col-sm-2 control-label">Sales types</label>
    <div class="col-sm-10">
	<select class="form-control" name="type" required>
	<option  value="all"  >Both Cash and Credit sales--</option>
   <option value="Cash">Cash Sales Only</option>
 <option value="Invoice">Credit/Invoice Sales Only</option>

									  
									  				


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

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



</div>
</div>














































