<?php
require "commonincludefiles.php";
//error_reporting(1);
ini_set('memory_limit', '-1');
require_once 'excel_reader2.php';

$fullpath=$_FILES['enrollment_upload']['tmp_name'];



$data = new Spreadsheet_Excel_Reader($fullpath);
$html="";
$i=0;
$n=1;
$r=1;
$more_record=0;	
$total=count($data->sheets[$i][cells]);
$sql="INSERT INTO `invoice_data` (`name`,`address`, `invoice_no`, `invoice_date`, `pan_no`, `particular`, `qty`, `unit_price`, `total`, `remark1`, `remark2`,`import_date`) VALUES "	;

	for($j=1;$j<=count($data->sheets[$i][cells]);$j++) // loop used to get each row of the sheet
		{
		
			$more_record=1;	
			$sql.='(';
				
			for($k=1;$k<=11;$k++) // This loop is created to get data in a table format.
			{
				$sql.="'".Escape($data->sheets[$i][cells][$j][$k])."',";
				
				
			}
				
			$sql.="'".date('Y-m-d h:i:sa"')."'";
				$sql.='),';
				

				if($r==1000000){
					$r=0;
					$sql = substr($sql, 0, strlen($sql)-1).';';	
					dbQuery($sql);					
					$more_record=0;	
					$sql = "";
				$sql="INSERT INTO `csc_customer` (`name`,`address`, `invoice_no`, `invoice_date`, `pan_no`, `particular`, `qty`, `unit_price`, `total`, `remark1`, `remark2`,`import_date`) VALUES "	;
				}
			$r++;
		
	}
	
	if($more_record==1){
		 $sql = substr($sql, 0, strlen($sql)-1).';';	

	 	dbQuery($sql);
		
	}

	echo'{"success":"true","msg":"Total '.$total.' row imported."}'; 
	exit;
	

  ?>