<?php
ini_set('error_reporting', 1);
ini_set('display_errors', true);

require_once '../excelimport/src/SimpleXLSX.php';
//include('../../database_connection.php');
include_once('../database_connection.php');
echo '<h1>PLEASE UPLOAD THE ITEM From EXCEL FORMAT</h1>';
/*if ( $xlsx = SimpleXLSX::parse('../../backup/voucher.xlsx')) {*/
if (isset($_FILES['file'])) {
    $ContractID=rand()*1000;
    //$VoucherTypeID=$_POST['VoucherType'];

    if ( $xlsx = SimpleXLSX::parse( $_FILES['file']['tmp_name'] ) ) {
        //echo "inside";
odbc_autocommit($connection, FALSE);
	// Produce array keys from the array values of 1st array element
	$header_values = $rows = [];
    $col=0;
    $VoucherID=0;//array();
    $fields=array();
    $fdetails=array();
    $VoucherDate='';
    $LedgerName='';
    $Credit=0;
    $Debit=0;
    $Remarks='';
    $InvoiceRef='';
    $dim = $xlsx->dimension();
        $cols = $dim[0];
    $cols=7;
    echo "<table>";
	foreach ( $xlsx->rows() as $k => $r ) {
                if ( $k === 0 ) {
            $header_values = $r;
            continue;
        }
        echo '<tr>';
            for ( $i = 0; $i < $cols; $i ++ ) {
                $coldata=( isset( $r[ $i ] ) ? $r[ $i ] : '&nbsp;' );
                echo '<td>' . $coldata . '</td>';
if($i==1)$Name=$coldata;
if($i==2)$Active=$coldata;
if($i==3)$CompanyID=$coldata;   
if($i==4)$Under=$coldata;
if($i==5)$Details=$coldata;
if($i==6)$price=$coldata;
if($i==7)$cost=$coldata;



            }
            echo '</tr>';
      

      }
      echo "</table>";

/* if (!odbc_error())
   {
      odbc_commit($connection);
      $res=array('status'=>"ok",'description'=>'Data Saved Sucessfully');
  }
else
{
  echo "here";
      odbc_rollback($connection);
      $res=array('status'=>"Error",'description'=>'Record  Not Updated');

}*/
                }




   

if (!odbc_error())
   {
      odbc_commit($connection);
      $res=array('status'=>"ok",'description'=>'Data Saved Sucessfully');
   //   echo "<script>alert('Item Saved Successfully');window.location='ItemUpload.php'</script>";
  }
else
{
      odbc_rollback($connection);
      $res=array('status'=>"Error",'description'=>'Record  Not Updated');
echo "<script>alert('Voucher FAILED TRY AGAIN');window.location='ItemUpload.php'</script>";
}
//unset($_FILES);

    //echo ($res); 
}//end file if
echo '<h2>Upload Item</h2>
<form method="post" enctype="multipart/form-data">
<table>
<tr>
<td>
*.XLSX <input type="file" name="file"  /></td><td>
&nbsp;&nbsp;<input type="submit" value="Upload" name="Upload" /></td>
</tr>
</table>
</form>';
