<?php
use Box\Spout\Reader\ReaderFactory;
use Box\Spout\Common\Type;
$connect = new PDO('pgsql:host=localhost;dbname=postgres', 'postgres', 'Kaushik@1610');
$connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
require_once ('Spout/Autoloader/autoload.php');
//====================================================================
$filePath = ('customer_mst.xlsx');
$reader = ReaderFactory::create(Type::XLSX);
$reader->open($filePath);
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
$result = $connect->query("DELETE FROM customer_mst");
if (($extension == 'xlsx' || $extension == 'xls')){
$count = 0;
	foreach ($reader->getSheetIterator() as $sheet){
		foreach ($sheet->getRowIterator() as $row){
			if($count > 0){
				$id = $count;
				$customer_name = $row[0];
				$customer_code = $row[1];
				$cust_address_one = $row[2];
				$cust_address_two = $row[3];
				$cust_address_three = $row[4];
				$cust_place = $row[5];
				$cust_pin_code = $row[6];
				$cust_st_code = $row[7];
				$cust_st_name = $row[8];
				$cont_person = $row[9];
				$cust_phone = $row[10];
				$cust_mobile = $row[11];
				$cust_email = $row[12];
				$cust_gstno = $row[13];
				$cust_pan_no = $row[14];
				$cust_aadhar_no = $row[15];
				$tax_code = $row[16];
				$opening = $row[17];
				$debit = $row[18];
				$credit = $row[19];
				$clbalance = $row[20];
				$transporter_name = $row[21];
				$bankname = $row[22];
				$bankaccno = $row[23];
				$bankaccname = $row[24];
				$ifsccode = $row[25];
				$due_days = $row[26];
				$remarks = $row[27];
				$qry = "INSERT INTO customer_mst(id,customer_name,customer_code,cust_address_one,cust_address_two,cust_address_three,cust_place,cust_pin_code,cust_st_code,cust_st_name,cont_person,cust_phone,cust_mobile,cust_email,cust_gstno,cust_pan_no,cust_aadhar_no,tax_code,opening,debit,credit,clbalance,transporter_name,bankname,bankaccno,bankaccname,ifsccode,due_days,remarks) VALUES ('$id','$customer_name','$customer_code','$cust_address_one','$cust_address_two','$cust_address_three','$cust_place','$cust_pin_code','$cust_st_code','$cust_st_name','$cont_person','$cust_phone','$cust_mobile','$cust_email','$cust_gstno','$cust_pan_no','$cust_aadhar_no','$tax_code','$opening','$debit','$credit','$clbalance','$transporter_name','$bankname','$bankaccno','$bankaccname','$ifsccode','$due_days','$remarks')";
				$result = $connect->query($qry);
			}
			$count++;
		}
	}
}
$reader->close();
header ("Location: index.php");
//====================================================================
?>
