<?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 = ('supplier_mst.xlsx');
$reader = ReaderFactory::create(Type::XLSX);
$reader->open($filePath);
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
$result = $connect->query("DELETE FROM supplier_mst");
if (($extension == 'xlsx' || $extension == 'xls')){
$count = 0;
	foreach ($reader->getSheetIterator() as $sheet){
		foreach ($sheet->getRowIterator() as $row){
			if($count > 0){
				$id = $count;
				$supplier_name = $row[0];
				$supplier_code = $row[1];
				$supplier_address_one = $row[2];
				$supplier_address_two = $row[3];
				$supplier_address_three = $row[4];
				$supplier_place = $row[5];
				$supplier_pin_code = $row[6];
				$supplier_st_code = $row[7];
				$supplier_st_name = $row[8];
				$cont_person = $row[9];
				$supplier_phone = $row[10];
				$supplier_mobile = $row[11];
				$supplier_email = $row[12];
				$supplier_gstno = $row[13];
				$supplier_pan_no = $row[14];
				$supplier_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 supplier_mst(id,supplier_name,supplier_code,supplier_address_one,supplier_address_two,supplier_address_three,supplier_place,supplier_pin_code,supplier_st_code,supplier_st_name,cont_person,supplier_phone,supplier_mobile,supplier_email,supplier_gstno,supplier_pan_no,supplier_aadhar_no,tax_code,opening,debit,credit,clbalance,transporter_name,bankname,bankaccno,bankaccname,ifsccode,due_days,remarks) VALUES ('$id','$supplier_name','$supplier_code','$supplier_address_one','$supplier_address_two','$supplier_address_three','$supplier_place','$supplier_pin_code','$supplier_st_code','$supplier_st_name','$cont_person','$supplier_phone','$supplier_mobile','$supplier_email','$supplier_gstno','$supplier_pan_no','$supplier_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");
//====================================================================
?>
