
 <link href="<?php echo base_url(); ?>assets/select/chosen.min.css" rel="stylesheet" media="screen">
	
		   
		   		   <script src="<?php echo base_url(); ?>assets/select/chosen.jquery.min.js"></script>

         <script type="text/javascript">
  
	  $(function() {
<!--             $(".datepicker").datepicker(); -->
<!--             $(".uniform_on").uniform() -->;
            $(".chzn-select").chosen();
   <!--          $('.textarea').wysihtml5(); -->

        });
</script>

 
 <div class="row">
  
   	

   	<div class="col-md-12">
	
  
		<div class="panel panel-default" data-collapsed="0">
        	<div class="panel-heading">
            	<div class="panel-title" id="redcolor" >
            		<i class="entypo-plus-circled"></i>
						 <span class="pull-right"> Follow-up history</span>	
                        <a  id="more" target="blank" class="btn btn-primary" href="<?php echo base_url();?>user/viedeals">back  </a>
						  <a data-toggle='modal' data-target='#colectionModal' class="btn btn-primary"> Download	Daily Follow-up</a>

 <a data-toggle='modal' data-target='#uploaddealModal' class="btn btn-default"> Upload 	Daily Follow-up</a>

				
            	</div>
            </div>
			<div class="panel-body">
			 <?php 
			$session_data = $this->session->userdata('logged_in');

    $session_data = $this->session->userdata('logged_in');
 $finalendate=date("Y-m-d H:59:59");
  $finalstartdate=date("Y-m-d 00:00:00");
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];


				 $mydate=date("Y-m-d");
				
				$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
			    $viewalldeals=$this->usermodel->populatuserpermissionsdataarray('deals','viewall',$userid);
  
  
  
  
        $attr = array("class" => "form-horizontal", "role" => "form", "id" => "search", "name" => "search");
        echo form_open("user/searchallfollowup", $attr);?>
            <div class="form-group">
			
                <div class="col-md-3">
				
				

     <div class="form-group">
    <label for="inputsearchterm" class="col-sm-2 control-label">Staff?</label>
    <div class="col-sm-10">
	<select class="chzn-select" name="searchterm" required>
	
	<option value=""  >---Select staff---</option>

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

   
 	$data['id'] = $session_data['id'];
        
		 $myuserid = $data['id'];
		if($usertype=="admin"){
			$allusers = $this->usermodel->populatealldatanoarray('people', 'companyid',$companyid,'status',1);
			?>
						<option value="all"  >All 	users</option>
<?php


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

 
  
 }
  ?>

	
	
	
	<?php 
				
				
	

	
if(is_array($allusers)) {

   foreach($allusers as $userrow){

   //echo $courserow->coursename;
    ?>
					<option  selected="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('searchterm'); ?>

	</div>
  </div>
				
                </div>
				
				
				    <div class="col-md-2">
		  		<input type="text" name="startdate" value="<?php echo set_value('startdate',$finalstartdate); ?>" class="form-control" required placeholder="Enter from date">

					</div>
				
				
				
				  <div class="col-md-2">
		  		<input type="text" name="closedate" value="<?php echo set_value('closedate',$finalendate); ?>" class="form-control" required placeholder="Enter TO date">

					</div>
					  <div class="col-md-2">
<select class="form-control" name="branchid"  id="branchid" required>
	
	
	<option value=""  >---Select Branch/Counter to Open--</option>

									
					<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.';
}
	
?>
</select>
					</div>
				
				
				
				
				
                <div class="col-md-3">
                    <input id="btn_search" name="btn_search" type="submit" class="btn btn-success" value="Search" />
                    <a href="<?php echo base_url(). "user/viewopeningstock"; ?>" class="btn btn-primary">Refresh</a>
                </div>
				 
            </div>
        <?php echo form_close(); ?>

        </div>	
			
			
			
			
			
			
			
			
			
			
			
			
			
			
								<div class="col-md-12">
       
				<div class="widget-content nopadding table_holder table-responsive" >				
	<?PHP


				echo $this->session->flashdata('msg'); 
								?>	
										
					<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>Follow</th>
		   <th>Due Date</th>
		   <th> Name</th>
         <th> Contact</th>
       

     <th> Level</th>
	    	     <th>Feedback</th>

	     <th>Recomendation</th>
		
<th>Added by:</th>
	  <th>Called Date/Status</th>

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

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='4'>";
    
       echo '<div class="alert alert-warning text-center">There no records found..</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
  
  	foreach ($viewallfollowups as $c): 

		 

             ?>



             <tr>
                
            <?php 
			$followupid=$c->followupid;

$id=$c->id;
			$type=$c->type;


?>




<td>

											   <a  id="more" target="_blank" class="btn btn-default" href="<?php echo base_url();?>user/viewfollowups?randomitemidentifier=<?php   {echo  $followupid;}  ?>&type=<?php   {echo  $type;}  ?>&currentid=<?php   {echo  $id;}  ?>">Follow-Up </a>

</td>

		    <td><?php 
echo $c->nextdate ;
$endate=$c->nextdate;
    		  $newDate = date('Y-m-d H:i:s');

	  //$newDate = date("Y-m-d");


		$mycurrentdate = strtotime(date($newDate));

	




$finaldate = strtotime(date($c->nextdate));
$exactdate = strtotime(date($c->nextdate));

									$secs = $mycurrentdate-$finaldate;// == <seconds between the two times>
									$days = $secs / 86400;
							 $finaldays=round($days,0);

if($c->status=="Dont Call"){
		?>
			<div class="btn-success">


			</div>
			<?php
	
	
}else{

			 ?>
			 
			 
			<?php 
			
			if($finaldays <= 0){
			
			
						if(($finaldays == -0) ||($finaldays == -1)) {

	$hours = (($secs / 3600)* -1);
															 $finalhrs=round($hours,0);

					?>
			<div class="btn-success">
			<?php  echo $finalhrs." Hr(s) Due" ; 	?>
			</div>
			<?php
	
						}else{
							?>
			<div class="btn-success">
			<?php  echo $finaldays." Due" ; 	?>
			</div>
			<?php
						}
			
			
			
			}else if(($finaldays > 0) && ($finaldays <3)) {
		?>
			<div class="btn-warning">
			<?php  echo $finaldays." Overdue"  ; 	?>
			</div>
			<?php
			
			}else if($finaldays >=3){
			?>
			<div class="btn-danger">
			<?php  echo $finaldays." Overdue" ; 	?>
			</div>
			<?php
			}else{
				
			?>
			<div class="btn-danger">
			<?php  echo $success." Overdue" ; 	?>
			</div>
			<?php	
				
			}
}
			?>	
			 
			 
			 
			 
			 
			 
			 
			 </td>












    <td><?php 

$view="";

	if($type=="Invoice"){
		
		$view="user/salesdue";

		$sales= $this->usermodel->populateallarray('sales','invoice',$followupid);

				$customer=$sales[0]["customer"];
						$people= $this->usermodel->populateallarray('people','id',$customer);
				echo$company=$people[0]["company"];


		
	}else if($type=="Customer"){
			$view="user/viewallcustomerdue";
		
	          		$details= $this->usermodel->populateallarray('people','id',$followupid);

				$owner=$details[0]["company"];

				$contactname=$details[0]["firstname"];
				if($owner==""){
									echo $contactname;

				}else{
					
					echo $owner;

				}
	}else{
			$view="user/viedeals";

      		$details= $this->usermodel->populateallarray('deals','id',$followupid);

				$owner=$details[0]["owner"];

				$contactname=$details[0]["contactname"];
				if($owner==""){
									echo $contactname;

				}else{
					
					echo $owner;

				}

	}		

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

	if($type=="Invoice"){
									
												echo$phone=$people[0]["phone"];
	
								}else if($type=="Customer"){
									
												echo$phone=$details[0]["phone"];
	
								}	else{
				echo$contact=$details[0]["contact"];
				
								}				

	?></td>

  

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


    <td><?php echo $c->feedback ; ?></td>
	    <td><?php echo $c->recommendation ; ?></td>
	


 <td><?php 
	$owner=$c->userid;
			$myowner = $this->usermodel->populateall('people', 'id',$owner);


	


if(is_array($myowner)) {

   foreach($myowner as $myowneryrow){
		echo $myowneryrow->firstname;


}} else {
    echo 'No User .';
}
	
?>
</td>
		  <td><?php echo $c->date ; ?>
		  	  
				
				
				
			          
                     <a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/activationfollowup?randomitemidentifier=<?php   {echo  $id;}  ?>&needed=<?php   {echo  $c->status;}  ?>&view=<?php echo$view?>">Clear

</a>

		 </td>
				
				
				</td>
             </tr>

	<?php endforeach;} ?>

           

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

        
        </div>						
				
									
									
									
					</div>	

					
					

	
	
	<div id="uploaddealModal" 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">Please Upload deily Followups</h4>
		
      </div>
      <div class="modal-body">
      
	  	

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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/uploadfollowups' , 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="child"id="type" class="form-control" required placeholder="Enter type">
				<input type="hidden" name="view" value="user/viewallfollowups"id="view" class="form-control" required placeholder="Enter view">
	
	
	<div class="form-group">
    <label for="inputsurname" class="col-sm-2 control-label">	CSV LIST</label>
    <div class="col-sm-10">
		
			<input type="file" name="file" width="400"  value="<?php echo set_value('file') ;?>" placeholder="Select EXCELL" class="form-control" required placeholder="Enter Surname"  >

		  		
				
		<span class="text-danger"> Upload correct format of CSV File  here..<?php echo form_error('file'); ?>
		
		</span>
	</div>
  </div>	
  
	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="followups" name="btn_uploadfollowups" class="btn btn-default">Upload Followups  </button>

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

    

				</div>

		</div>
	    </div>
    </div>
	
	
	<div id="colectionModal" 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">Download Daily Follow-up</h4>
      </div>
      <div class="modal-body">
      
	  	

				<?PHP
//$session_data = $this->session->userdata('logged_in');
 //$mydate=date("Y-m-d");
 					 // $mydate=date("Y-m-d H:i:s");
 $fromdate=date("Y-m-d 00:00:00");


				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/downloaddailyfollowups' , 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;?>

	
	
	 <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="branchid"  id="branchid" required>
	
	
	<option value=""  >---Select Branch/Counter Name--</option>
<?php
									 if( $viewalldeals==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>
	
  <div class="form-group">
    <label for="inputstartdate" class="col-sm-2 control-label">From Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="startdate" value="<?php echo set_value('startdate',$finalstartdate); ?>" class="form-control" required placeholder="Enter start date">
		 
				
		<span class="text-danger"> <?php echo form_error('startdate'); ?>
		
		</span>
	</div>
  </div>
  
  	<div class="form-group">
    <label for="inputclosedate" class="col-sm-2 control-label">	To Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="closedate" value="<?php echo set_value('closedate',$finalendate); ?>" class="form-control" required placeholder="Enter End date">
		 
				
		<span class="text-danger"> <?php echo form_error('closedate'); ?>
		
		</span>
	</div>
  </div>
  
  
   
	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="deal" name="btn_downloadfollowups" class="btn btn-primary"> Download Follow-up</button>

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

    

				</div>

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

	
	
	

					
					
					
					
					
					
					
					
								
<div id="addModal" 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">Add new Category</h4>
      </div>
      <div class="modal-body">
      
	  	

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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/addcategory' , 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;?>
				  		
	<div class="form-group">
    <label for="inputname" class="col-sm-2 control-label">	Name </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="name" value="<?php echo set_value('name'); ?>" class="form-control" required placeholder="Enter name">
		 
				
		<span class="text-danger"> <?php echo form_error('name'); ?>
		
		</span>
	</div>
  </div>

	<div class="form-group">
    <label for="inputdescription" class="col-sm-2 control-label">	Description</label>
    <div class="col-sm-10">

				<textarea name="description" value="<?php echo set_value('description'); ?>"  class="form-control"  placeholder="Enter description"></textarea>
			
		<span class="text-danger"> <?php echo form_error('description'); ?>
		
		</span>
	</div>
  </div>
		

	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="category" name="btn_addcategory" class="btn btn-primary"> Add Category   </button>

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

    

				</div>

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





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

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

 
</div>


















