<?php 
session_start();
include '../db.php';
include("../all_query.php");
 error_reporting(0); 
set_time_limit(0);
ini_set('max_execution_time', 0);

 if(isset($_SESSION['loan_crm_username']) && isset($_SESSION['loan_crm_password']))
{
	
	 	
		
	
	?>
	
	
<!DOCTYPE html>
 
<html lang="en" class="light-style layout-navbar-fixed layout-menu-fixed " dir="ltr" data-theme="theme-bordered" data-assets-path="../assets/" data-template="vertical-menu-template-bordered">
 
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />

    <title>CRM</title>
     
    <meta name="description" content="Start your development with a Dashboard for Bootstrap 5" />
    <meta name="keywords" content="dashboard, bootstrap 5 dashboard, bootstrap 5 design, bootstrap 5">
    <!-- Canonical SEO -->
    <link rel="canonical" href="https://1.envato.market/frest_admin">
    
    <!-- Favicon -->
    <link rel="icon" type="image/x-icon" href="https://pixinvent.com/demo/frest-clean-bootstrap-admin-dashboard-template/assets/img/favicon/favicon.ico" />

    <!-- Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com/">
    <link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&amp;family=Rubik:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&amp;display=swap" rel="stylesheet">

    <!-- Icons -->
    <link rel="stylesheet" href="../assets/vendor/fonts/boxicons.css" />
    <link rel="stylesheet" href="../assets/vendor/fonts/fontawesome.css" />
    <link rel="stylesheet" href="../assets/vendor/fonts/flag-icons.css" />

    <!-- Core CSS -->
    <link rel="stylesheet" href="../assets/vendor/css/rtl/core.css" class="template-customizer-core-css" />
    <link rel="stylesheet" href="../assets/vendor/css/rtl/theme-bordered.css" class="template-customizer-theme-css" />
    <link rel="stylesheet" href="../assets/css/demo.css" />

    <!-- Vendors CSS -->
    <link rel="stylesheet" href="../assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.css" />
    <link rel="stylesheet" href="../assets/vendor/libs/typeahead-js/typeahead.css" />
    <link rel="stylesheet" href="../assets/vendor/libs/datatables-bs5/datatables.bootstrap5.css">
<link rel="stylesheet" href="../assets/vendor/libs/datatables-responsive-bs5/responsive.bootstrap5.css">
<link rel="stylesheet" href="../assets/vendor/libs/datatables-buttons-bs5/buttons.bootstrap5.css">

    <!-- Page CSS -->
    
    <!-- Helpers -->
    <script src="../assets/vendor/js/helpers.js"></script>

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
   
   
    <!--! Template customizer & Theme config files MUST be included after core stylesheets and helpers.js in the <head> section -->
    <!--? Template customizer: To hide customizer set displayCustomizer value false in config.js.  -->
     <!--? Config:  Mandatory theme config file contain global vars & default theme options, Set your preferred theme option in this file.  -->
    <script src="../assets/js/config.js"></script>
    
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async="async" src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
    <script>
    window.dataLayer = window.dataLayer || [];

    function gtag() {
      dataLayer.push(arguments);
    }
    gtag('js', new Date());
    gtag('config', 'GA_MEASUREMENT_ID');
    </script>
    <!-- Custom notification for demo -->
    <!-- beautify ignore:end -->

</head>
<body>

	   
	    <?php
 require("phpexcel/php-excel-reader/excel_reader2.php");
	require('phpexcel/SpreadsheetReader.php');
	
	$uploded=0;
 
 $insert_count=0;
 $duplicate_count=0;
 $update_count=0;
 
 $total_uploded = 0;
 $error_rows = array();
			
   if(isset($_POST['upload_excel']))
   {
	   $filename=$_FILES['excelfile']['name'];
	   move_uploaded_file($_FILES['excelfile']['tmp_name'],'excel/'.$filename);
	   
	   date_default_timezone_set('UTC');

	$StartMem = memory_get_usage();


     $headerArray = array();

	try
	{
		$Filepath="excel/".$filename;
		$Spreadsheet = new SpreadsheetReader($Filepath);
		$BaseMem = memory_get_usage();
		
		$date_time = date('Y-m-d H:i:s');
					

		$Sheets = $Spreadsheet -> Sheets();

           mysqli_query($conn,"delete from `payments` " );
				   
		foreach ($Sheets as $Index => $Name)
		{
			

			$Time = microtime(true);

			$Spreadsheet -> ChangeSheet($Index);
			
			
            $line=0;
			
			$uploded = 1;
			
			foreach ($Spreadsheet as $Key => $Row)
			{
				$line++;
				
				
				
				
					/**  Get Excel Headers ***/
					
					if($line==1)
					{
						if ($Row)
						{
							
							$g=0;
							foreach($Row as $header_name)
							{
							    $title = strtolower($header_name);
								$title = str_replace(' ','_',$title);
								$title = str_replace('-','_',$title);
								$title = str_replace('/','_',$title);
								$title = str_replace('#','no',$title);
								 
								
								
							  $headerArray[$g]  = $title;
							  
							  $g++;
							}
							
						}
				
				
				   //  echo implode(',',$headerArray);
						
					}
					
					
				 
					
					
					
					
				
				if($line!=1) {
					
					
					
					
					
					
					
				if ($Row)
				{
					
			
			//$data = explode(',',$table_fieldsData['column_names']);
                                
					  $p=0;
				
				$RECORD=array();
				 foreach($headerArray as $field)
					  {    
											 
					if($field!='id' && $field!='date_time' && $field!='status' )
					  {  
					
					
					$string = trim(preg_replace('/\s\s+/', ' ', $Row[$p]));
					  
					$RECORD[$field] = stripslashes($string);
					
					  $p++;
					
					  }
					  
					  }
				
				
				$save = 1;
					 

               if($save == 1)
			   {
				   
				  
				  
				  $account_id = $RECORD['accountid'];
				  
				  $leadQ  = mysqli_query($conn,"select *from `leads` where account_id = '$account_id' ");
				  $leadData = mysqli_fetch_assoc($leadQ);
				  
				  $account_holder_id = $leadData['account_holder_id'];
				  
				  $customerQ = mysqli_query($conn,"select *from `customer` where account_holder_id = '$account_holder_id' ");
				  $customerData = mysqli_fetch_assoc($customerQ);
				  
				  $advisor = $customerData['advisor'];
				  
				  $RECORD['account_holder_id'] = $account_holder_id;
				  $RECORD['advisor'] = $advisor;
				  
				  
				   insertTable($conn,'payments',$RECORD,'add_submit');
				   
				   
				    $total_uploded++;
					
					 
			   }
	 
					
				}
				}
				
			}
		
			
		}
		
		
		if(count($error_rows) == 0)
		{
		
		$_SESSION['save_message'] = "Total uploaded records: $total_uploded ";
		$import_description = "Total uploaded records: $total_uploded ";
		}
		else
		{
			$_SESSION['save_message'] = "Total uploaded records: $total_uploded , Error In Rows:".implode(',',$error_rows);
		$import_description = "Total uploaded records: $total_uploded , Error In Rows:".implode(',',$error_rows);
		}
		
		
		
		
		
	}
	catch (Exception $E)
	{
		die("Invalid Excel Format");
	}
	   
	   
	   
   }
  
 
 
 ?>




  <!-- Layout wrapper -->
<div class="layout-wrapper layout-content-navbar  ">
  <div class="layout-container">

    
    




<!-- Menu -->

<?php include('left_sidebar.php'); ?>

<!-- / Menu -->

    

    <!-- Layout container -->
    <div class="layout-page">
      
      



<!-- Navbar -->

  
<?php include('header.php'); ?>



  
<!-- / Navbar -->
   
   <script>
   $(document).ready(function(){

     $('#myTable').DataTable( {
			  "ordering": false,
        dom: 'Bfrtip',

        buttons: 
		[
			
	  	  
	  {
        extend: 'copy',
       
		
      } , 
	  {
        extend: 'csv',
       
		
      } ,			
	  {
        extend: 'excel',
      
		
      },			
	  {
        extend: 'pdf',
       
		
      } , {
        extend: 'print',
		       

		
      } 
	  
	  
	  
	  ]
    } );
});
   </script>

      

      <!-- Content wrapper -->
      <div class="content-wrapper">

          <!-- Content -->
        
          <div class="container-xxl flex-grow-1 container-p-y">
            
            
<h4 class="py-3 breadcrumb-wrapper mb-4">
  <span class="text-muted fw-light">Evalution Submitted /</span> List
</h4>


 <a href="../export_to_excel.php?type=call_evaluation" style="color:green;text-decoration:underline" ><i class="fa fa-download"></i>Export Call evaluation</a> &nbsp;&nbsp;
					   

  
 <?php if(isset($_SESSION['save_message'])) { ?> <div style="width:100%;" class="alert alert-success"><?php echo $_SESSION['save_message']; unset($_SESSION['save_message']); ?></div> <?php  }  ?>
			
			
 
					   
	   <br/>
					   
	<!-- Invoice List Table -->
	<div class="card">


   <script>
 
 function deleteSelected(table)
 {
	 
	 if(confirm('Are you sure?'))
	 {
		   var dataArr = [];
		   
		 $("input:checkbox[name=delete_checkbox]:checked").each(function(){
    dataArr.push($(this).val());
});
		 
		 
		  var jsonString = JSON.stringify(dataArr);
		  
		  
		   if(dataArr.length == 0)
			  
			  {
				  toastr.warning("Please Select Record!"); 
			  }
			  else {
				  
				  
		    $.ajax({
      type: "POST",
      url: 'delete_records_ajax.php',
	    data: {record_ids:jsonString,table:table},
      success: function(data) {
	
	    // toastr.warning(data.trim()); 
		  
		 window.location="";
		 
		
		 }
		  // <- this turns it into synchronous

		  }
	   );
			  }
		  
		  
	 }
	 
	 
 }
 
 
 
 function selectAll()
 {
	 
	 if($("input:checkbox[name=delete_checkbox]").prop('checked') == true)
	 {
		  $("input:checkbox[name=delete_checkbox]").prop('checked', false);
	 }
	 
	 else{
	 $("input:checkbox[name=delete_checkbox]").prop('checked', true);
	 }
 }


</script>	





			<div class="table-responsive" style="background:white;">
									
									
								 <!---  TABLE HERE  -->
  
<?php $pg=0; if(isset($_GET['page'])) { $pg=$_GET['page']; } ?>
  
  <script>
  
  $( document ).ready(function() {
  // Handler for .ready() called.
  
  fetchAllParty(<?php echo $pg; ?>,'','');
  
});
   </script>
  
  <script>
  
  
 
 function fetchAllParty(page,keyword,key_for){
	  
	//alert('a');
	
		
	 $('#add-row').addClass('loading');
	 
    $.ajax({
      type: "GET",
      url: 'get_call_evalution_table_ajax.php',
      data: ({page:page,keyword:keyword,key_for:key_for}),
      success: function(data) {
		
			document.getElementById('table_data_here').innerHTML=data;
			
			
				var c=0;
				
				 
  
			
			
		 }
		  // <- this turns it into synchronous

		  }
	   );
	   
	}


  
  </script>











  <p align="right"> Search: <input value="<?php if(isset($_GET['keyword'])) {  echo $_GET['keyword'];} ?>" onkeyup="fetchAllParty(0,this.value,'');" type="text" id="search_party"/></p>
		   
		   
         <div class="card-body1 loading">
		 <div id="table_data_here">
		 
		  <table class="loading" ><tr><td></td></tr></table>
		  
		  
		   </div>
		 </div>	
		 
 
					   
 
</div>


            
          </div>
          <!-- / Content -->
        
          
 
          
      
         </div>
        <!-- Content wrapper -->
      </div>
      <!-- / Layout page -->
    </div>

    
    
    
  </div>
  <!-- / Layout wrapper -->

 

  <!-- Core JS -->
  <!-- build:js assets/vendor/js/core.js -->
  <script src="../assets/vendor/libs/jquery/jquery.js"></script>
  <script src="../assets/vendor/libs/popper/popper.js"></script>
  <script src="../assets/vendor/js/bootstrap.js"></script>
  <script src="../assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.js"></script>
  <script src="../assets/vendor/libs/hammer/hammer.js"></script>
  <script src="../assets/vendor/libs/i18n/i18n.js"></script>
  <script src="../assets/vendor/libs/typeahead-js/typeahead.js"></script>
  
  <script src="../assets/vendor/js/menu.js"></script>
  <!-- endbuild -->

  <!-- Vendors JS -->
  <script src="../assets/vendor/libs/moment/moment.js"></script>
<script src="../assets/vendor/libs/datatables/jquery.dataTables.js"></script>
<script src="../assets/vendor/libs/datatables-bs5/datatables-bootstrap5.js"></script>
<script src="../assets/vendor/libs/datatables-responsive/datatables.responsive.js"></script>
<script src="../assets/vendor/libs/datatables-responsive-bs5/responsive.bootstrap5.js"></script>
<script src="../assets/vendor/libs/datatables-buttons/datatables-buttons.js"></script>
<script src="../assets/vendor/libs/datatables-buttons-bs5/buttons.bootstrap5.js"></script>

  <!-- Main JS -->
  <script src="../assets/js/main.js"></script>

  <!-- Page JS -->
  <script src="../assets/js/app-invoice-list.js"></script>
</body>

 
</html>
  <?php  }  else { header("Location:login.php");  } ?>