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

require '../excelimport/src/SimpleXLSX.php';
//include('../../database_connection.php');
include_once('../database_connection.php');
echo '<h1>PLEASE UPLOAD THE Hotel Booking IN EXCEL FORMAT</h1>';
/*if ( $xlsx1 = SimpleXLSX::parse('../backup/purchasedata.xlsx')) {*/
if (isset($_FILES['file1'])) {
    
    $VoucherTypeID=71;//$_POST['VoucherType'];

     //   echo "here";
    if ($xlsx1 = SimpleXLSX::parse( $_FILES['file1']['tmp_name'] ) ) {
     /* if(1==1)
      {*/
       // 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;
    $isError=0;
    $Remarks='';
    $InvoiceRef='';
    $Reference='-';
//    print_r($xlsx1->rows());
 ///   return;
    //break;
	foreach ( $xlsx1->rows() as $k => $r ) {
                if ( $k === 0 ) {
            $header_values = $r;
            continue;
        }
         $VID=$r[2];//."<br>";
         if($VID==null || $VID=="") continue;
                 // 0 - Voucher ID 
        // 1 - Date 
        // 2 - Narration 
        // 3 - Invoice Ref(Reference)
        // 4 - Ledger 
        // 5 - Debit 
        // 6 - Credit 
        // 7 - Remarks

//echo "vid=".$VID."-- REfe".$Reference;
        if($VID!=$Reference  && $VID!="")
         {
/*            if($VoucherID!="" && $VoucherID!=null)
    {
      $Narration=str_replace("'", " ", $Narration);
      $Narration=str_replace("*", "X", $Narration);
      $Narration=str_replace("%", " pert ", $Narration);
      $updatesql="update voucherdetails set Narration='$Narration' where VoucherID=$VoucherID";
    odbc_exec($connection,$updatesql) or die(odbc_error().$sql);
    }*/

         $Narration='';
            $ChequeNo='';
            $ChequeDate=Date("Y-m-d");
       //     $VoucherTypeID=7;
            $ReferenceInvoiceID=0;
            $VoucherNo='test--001';
            $NetAmount=0;
            $ChequeDate=Date("Y-m-d");
            $VoucherDate=trim($r[6]);
            //insert old Voucher here 
            // Insert Voucher Master 
           // $VoucherID=getMaxId("vouchermaster","VoucherID",$connection)+1; //
           // $VID=$VoucherID;
            //code for VoucherNo 
            $InvoiceType=5;
    if($InvoiceType==5)
        {
          $KeyField=generateCode("InvoiceMaster","KeyField","InvoiceType=5",$connection)+1;
          $KeyField=str_pad($KeyField,7,"0",STR_PAD_LEFT);
          $KeyField="Book-".Date("Y-m-d")."-".$KeyField;
        }
        
            //end Code for Voucher no 
        //taking from sheet 
        $VID=$r[2];//."<br>";
        $InvoiceDate=($r[6]);//Invoice date

        if($InvoiceDate!="")
        {

            $vd=explode("/",$InvoiceDate);
             // $vd=$vd[0];

            //$vd1=implode("-",$vd);
           // $dt=Date($vd);
            //echo "Print Date :";
            // $vd=explode("-",$vd); 
         //   print_r($vd);
           // break;
            $temp=str_replace("-","",$vd[0]) ;//day
            $temp=str_replace("00:00:00","",$temp);
            $mt=trim(str_replace("00:00:00","",$vd[1]));//month
            $yt1=str_replace("-","",$vd[2]);//Year

/*    if($temp<10)$temp='0'.$temp;
             if($mt<10)$mt='0'.$mt;*/
             $InvoiceDate=$yt1."-".$mt."-".$temp;

        //$DueDate=str_replace("00:00:00","",$DueDate);
       //     $DueDate=str_replace("--","",$DueDate);
//print_r($InvoiceDate);
//break;
        
        }
        else
        {
         
                odbc_rollback($connection);
      $res=array('status'=>"Error",'description'=>'Record  Not Updated');
echo "<script>alert('Voucher Check IN Not Available in row No ".($k+1)."');</script>";
$isError=1;
//window.location='BookingUpload.php'
break;
        
        }
        $DueDate=($r[7]);//Due date
        if($DueDate!="")
        {
            $vd=explode("/",$DueDate);
              $vd=$vd[0];

            //$vd1=implode("-",$vd);
           // $dt=Date($vd);
            //echo "Print Date :";
             $vd=explode("-",$vd); 
            /*print_r($vd);
            break;*/
            $temp=str_replace("-","",$vd[1]) ;//day
            $temp=str_replace("00:00:00","",$temp);
            $mt=trim(str_replace("00:00:00","",$vd[2]));//month
            $yt1=str_replace("-","",$vd[0]);//Year

/*    if($temp<10)$temp='0'.$temp;
             if($mt<10)$mt='0'.$mt;*/
             $DueDate=$yt1."-".$mt."-".$temp;

        //$DueDate=str_replace("00:00:00","",$DueDate);
       //     $DueDate=str_replace("--","",$DueDate);
//print_r($DueDate);
//break;
        }
        else
        {
                odbc_rollback($connection);
      $res=array('status'=>"Error",'description'=>'Record  Not Updated');
echo "<script>alert('Check out Not Available in row No ".($k+1)."');</script>";//window.location='BookingUpload.php'
$isError=1;
break;
        }
//return ;
//break;
        $SupplierName=$r[1];        
        $CustomerName=$r[2];        
        $ItemQty=$r[8];
        $ItemUnitPrice=$r[9];
        $NetAmount=$r[10];
        $ItemID=$r[13];
       //$SupplierLedgerID=$r[9];
        $ItemName=$r[13];
       /* $ProductCode=$r[11];
        $ItemUnitPrice=$r[12];
        $ItemQty=$r[13];
        $ItemSubTotal=$r[14];*/
        $TotalTaxAmount=0;//($NetAmount-$TotalAmount);
        //$PurchaseOrderNo=$r[17];
        //$Remarks=$r[18];//memo
        //echo "Room Type=".
        $RoomTypeID=$r[16];
        //break;
        //end taking from sheet
        $GodownID=1;
        $Narration=str_replace("'"," ", $ItemName)."---".$VID;
        $ClientBankAccountName=$VID;
/*$PurchaseLedgerID=getnamesingle("Accounts","COAID","COANAME","'".$PurchaseLedgerID."' and [group]=0",$connection);
        $PurchaseLedgerID=($PurchaseLedgerID!="")?$PurchaseLedgerID:0;*/
        if($RoomTypeID>0 && $RoomTypeID!=""){
//echo $RoomTypeID;
$RoomTypeID=getnamesingle("inventory","ID","ItemType","".$RoomTypeID." and [group]=1",$connection);
//break;
if($RoomTypeID=="")
                {
                odbc_rollback($connection);
      $res=array('status'=>"Error",'description'=>'Record  Not Updated');
      $isError=1;
      break;
echo "<script>alert('Room Type Data Invalid in row No ".($k+1)."');</script>";

//window.location='BookingUpload.php'
        }
        }
        else
        {
                  $isError=1;
                odbc_rollback($connection);
      $res=array('status'=>"Error",'description'=>'Record  Not Updated');
echo "<script>alert('Room Type Data Invalid  in row No ".($k+1)."');</script>";
//window.location='BookingUpload.php'
        
      break;      
        }
//break;
        $SupplierLedgerID=getnamesingle("Accounts","COAID","COANAME","'".$SupplierName."' and [group]=0",$connection);
        if($SupplierLedgerID=="")
        {
$isError=1;
                odbc_rollback($connection);
      $res=array('status'=>"Error",'description'=>'Record  Not Updated');
echo "<script>alert('CustomerName Invalid in row No ".($k+1)."');</script>";
//window.location='BookingUpload.php'
 
        }
        $SupplierLedgerID=($SupplierLedgerID!="")?$SupplierLedgerID:0;
$InvoiceID=getMaxId("InvoiceMaster","InvoiceID",$connection)+1;
$GodownID=1;
$SupplierID=$SupplierLedgerID;
$Active=1;
$InvoiceType=5;
$CreateLog='Admin';
$Posted=1;
$Paid=0;
//echo "ItemID=".$ItemID;

if($ItemID!="")
{
 $ItemID=getnamesingle("inventory","ID","Name","'".$ItemID."'",$connection);
 $InvoiceStatus=2;
 //Booking
}
else{
  $InvoiceStatus=1;//Reservation 
  $ItemID=$RoomTypeID;
}

$BranchID=1;
//$CustomerName="";
 $sql="insert into InvoiceMaster (InvoiceID,InvoiceDate,DueDate,TotalAmount,NetAmount,InvoiceType,KeyField,CreateLog,Posted,CustomerName,Paid,Active,SupplierID,GodownID,InvoiceStatus,BranchID) values($InvoiceID,'$InvoiceDate','$DueDate',$NetAmount,$NetAmount,$InvoiceType,'$KeyField','$CreateLog',$Posted,'$CustomerName',$Paid,$Active,$SupplierID,$GodownID,$InvoiceStatus,$BranchID)";
odbc_exec($connection,$sql) or die(odbc_error().$sql);
//code for invoice detail
   $sql="insert into invoicedetail (InvoiceID,ItemID,UnitPrice,Qty,Amount,NetAmount,UnitID,InvoiceDate,DueDate,BranchID) values($InvoiceID,$ItemID,$ItemUnitPrice,$ItemQty,$NetAmount,$NetAmount,1,'$InvoiceDate','$DueDate','$BranchID')";
odbc_exec($connection, $sql) or die(odbc_error().$sql);
//continue;

/*$sql="select * from InvoiceMaster where VoucherID=$VoucherID";
$result=odbc_exec($connection,$sql);
if(odbc_num_rows($result)>0)
$VoucherID=$VoucherID+1;
*/
if($InvoiceStatus==2)
{
$VoucherID=getmaxId("VoucherMaster","VoucherID",$connection)+1;
      $VoucherNo="";
        if($VoucherTypeID==71)
        {
          $VoucherNo=generateCode("vouchermaster","VoucherNo","VoucherTypeID=71",$connection)+1;
          $VoucherNo=str_pad($VoucherNo,5,"0",STR_PAD_LEFT);
          $VoucherNo="BK-".$VoucherNo;
        }
  $fields['VoucherID']=$VoucherID;
           $fields['VoucherNo']=$VoucherNo;//isset($VoucherNo)?$VoucherNo:0;
           $fields['TotalAmount']=isset($NetAmount)?$NetAmount:0;
           $fields['Active']=1;//isset($Active)?$Active:0;
           $fields['VoucherDate']=($VoucherDate!="")?$VoucherDate:date("Y-m-d");
           $fields['Narration']=isset($Narration)?$Narration:0;
           $fields['Posted']=1;//isset($Posted)?$Posted:0;
           $fields['IsPostDated']=0;//isset($IsPostDated)?$IsPostDated:0;
           $fields['ChequeNo']=($ChequeNo!="")?$ChequeNo:0;
        $fields['ClientBankAccountName']=($ClientBankAccountName!="")?$ClientBankAccountName:0;
        $StatusID=0;
           $fields['ChequeStatus']=($StatusID!="")?$StatusID:0;
           $fields['ChequeDate']=($ChequeDate!="")?$ChequeDate:date("Y-m-d");
           $fields['isVoucherReturnCheque']=0;//isset($IsPostDated)?$IsPostDated:0;
           $fields['VoucherTypeID']=$VoucherTypeID;//isset($VoucherTypeID)?$VoucherTypeID:0;
           $fields['PeriodID']=1;//isset($PeriodID)?$PeriodID:0;
           $fields['ReferenceInvoiceID']=isset($InvoiceID)?$InvoiceID:0;
           $fields['SupplierID']=0;//isset($SupplierID)?$SupplierID:0;
           $fields['LedgerID']=isset($SupplierLedgerID)?$SupplierLedgerID:0;
           $fields['AmountDebit']=isset($AmountDebit)?$AmountDebit:0;
           $fields['AmountCredit']=isset($AmountCredit)?$AmountCredit:0;
           $fields['IsAuto']=1;//isset($IsAuto)?$IsAuto:0;
           $fields['LocationID']=isset($GodownID)?$GodownID:1;
           $fields['ReferenceVoucherID']=isset($ChequeDetailID)?$ChequeDetailID:0;
           $fields['GroupID']=isset($GroupID)?$GroupID:0;
           $fields['MultiVoucher']=0;//isset($MultiVoucher)?$MultiVoucher:0;
           $fields['VoucherToBePosted']=1;//isset($VoucherToBePosted)?$VoucherToBePosted:0;
           $fields['Cash']=0;//isset($Cash)?$Cash:0;
           $fields['ContractID']=0;//isset($ContractID)?$ContractID:0;
           $fields['UserID']=isset($_SESSION['UserID'])?$_SESSION['UserID']:0;
           $fields['VoucherDateTime']=isset($VoucherDateTime)?$VoucherDateTime:date("Y-m-d H:i:s");
           $fields['PaymentType']=isset($PaymentType)?$PaymentType:$Remarks;
         //  print_r($fields);
         //   InsertVoucherMaster($fields,$InvoiceType,$InvoiceID,$connection);   
        echo $sql="INSERT INTO [dbo].[VoucherMaster]
           ([VoucherID]
           ,[VoucherNo]
           ,[TotalAmount]
           ,[Active]
           ,[VoucherDate]
           ,[Narration]
           ,[Posted]
           ,[IsPostDated]
           ,[VoucherTypeID]
           ,[PeriodID]
           ,[ReferenceInvoiceID]
           ,[LedgerID]
           ,[AmountDebit]
           ,[AmountCredit]
           ,[IsAuto]
           ,[LocationID]
           ,[ReferenceVoucherID]
           ,[GroupID]
           ,[MultiVoucher]
           ,[VoucherToBePosted]
           ,[Cash]
           ,[ContractID]
           ,[UserID]
           ,[VoucherDateTime]
           ,[PaymentType],CreateLog,ChequeNo,ClientBankAccountName,ChequeTypeStatus,isVoucherReturnCheque,ChequeDate,DD)
     VALUES(".$fields['VoucherID']."
           ,'".$fields['VoucherNo']."'
           ,".$fields['TotalAmount']."
           ,".$fields['Active']."
           ,'".$fields['VoucherDate']."'
           ,'".$fields['Narration']."'
           ,".$fields['Posted']."
           ,".$fields['IsPostDated']."
           ,".$fields['VoucherTypeID']."
           ,".$fields['PeriodID']."
           ,".$fields['ReferenceInvoiceID']."
           ,".$fields['SupplierID']."
           ,".$fields['AmountDebit']."
           ,".$fields['AmountCredit']."
           ,".$fields['IsAuto']."
           ,".$fields['LocationID']."
           ,".$fields['ReferenceVoucherID']."
           ,".$fields['GroupID']."
           ,".$fields['MultiVoucher']."
           ,".$fields['VoucherToBePosted']."
           ,".$fields['Cash']."
           ,".$fields['ContractID']."
           ,".$fields['UserID']."
           ,'".$fields['VoucherDateTime']."'
           ,'".$fields['PaymentType']."','".$_SESSION['UserName']."',
           '$ChequeNo',0,0,0,'$ChequeDate','$VID'
     )";
//     break;
           odbc_exec($connection,$sql) or die(odbc_error().$sql);  
            $Reference=$VID;
            // insert voucher details 
                    
            // Insert Voucher Details here 
            $fdetails=array();  
        // VAT ENTRY 
            $VATLedgerID=236;
           $fdetails['VoucherID']=$VoucherID;
           $fdetails['LedgerID']=$VATLedgerID;//$d->CustomerLedgerID; DEbit side entry
            $Debit=$TotalTaxAmount;
            $Credit=0;//$TotalTaxAmount;
            //$CreditLedgerID=$CHEQUEINHAND;
            $CreditLedgerID=0;//$SupplierLedgerID;    
        $PurchaseLedgerID=0;
           $fdetails['Debit']=$Debit;
           $fdetails['Credit']=$Credit;
           $fdetails['Narration']='Hotel Booking';//$fields['Narration'];
           $fdetails['ReferenceInvoiceID']=isset($InvoiceID)?$InvoiceID:0;
           $fdetails['CreditLedgerID']=$CreditLedgerID;
           $fdetails['CostCenterID']=$GodownID;//company
           $fdetails['ChequeNo']=$ChequeNo;
           $fdetails['DD']=$VID;
           $fdetails['IsDelete']=0;
           $fdetails['DebitCostCenterID']=$GodownID;//company
           $fdetails['TransactionType']="Booking : ".$KeyField;   
           //print_r($fdetails);
       InsertVoucherDetail($fdetails,$InvoiceType,$VoucherID,$connection);      
//end VAT ENTRY 
       // Supplier ENTRIES 
       $Debit=$NetAmount;//$TotalAmount;
       $Credit=0;
$fdetails['VoucherID']=$VoucherID;
        if($Debit>0)
        {
        $fdetails['LedgerID']=$PurchaseLedgerID;//$d->CustomerLedgerID; DEbit side entry
        $CreditLedgerID=0;//$SupplierLedgerID;    
        }
        else
        {
        $fdetails['LedgerID']=$PurchaseLedgerID;//$d->CustomerLedgerID; DEbit side entry
        $CreditLedgerID=0;//$SupplierLedgerID;    
        }
        
        $GodownID=1;
           $fdetails['Debit']=$Debit;
           $fdetails['Credit']=$Credit;
           $fdetails['Narration']=$Narration.$InvoiceRef;
           $fdetails['ReferenceInvoiceID']=0;
           $fdetails['CreditLedgerID']=$CreditLedgerID;
           $fdetails['CostCenterID']=$GodownID;//company
           $fdetails['ChequeNo']='';
           $fdetails['DD']=$VID;
           $fdetails['IsDelete']=0;
           $fdetails['DebitCostCenterID']=$GodownID;//company
           $fdetails['TransactionType']=$Remarks;   
     //      InsertVoucherDetail($fdetails,$InvoiceType,$VoucherID,$connection);      

$Debit=$NetAmount;
       $Credit=$NetAmount;
$fdetails['VoucherID']=$VoucherID;
        if($Debit>0)
        {
        $fdetails['LedgerID']=$SupplierLedgerID;//$PurchaseLedgerID;//$d->CustomerLedgerID; DEbit side entry
        $CreditLedgerID=6;    
        }
        else
        {
        $fdetails['LedgerID']=$SupplierLedgerID;//$PurchaseLedgerID;//$d->CustomerLedgerID; DEbit side entry
        $CreditLedgerID=6;    
        }
        
        $GodownID=1;
           $fdetails['Debit']=$Debit;
           $fdetails['Credit']=$Credit;
           $fdetails['Narration']=$Narration.$InvoiceRef;
           $fdetails['ReferenceInvoiceID']=$InvoiceID;
           $fdetails['CreditLedgerID']=$CreditLedgerID;
           $fdetails['CostCenterID']=$GodownID;//company
           $fdetails['ChequeNo']='';
           $fdetails['DD']=$VID;
           $fdetails['IsDelete']=0;
           $fdetails['DebitCostCenterID']=$GodownID;//company
           $fdetails['TransactionType']=$Remarks;   
           InsertVoucherDetail($fdetails,$InvoiceType,$VoucherID,$connection);      
       //end SUPPLIER ENTERIES
//            echo "<br>New Document # ".$VID;
            $Reference=$VID;
            $Narration=($Narration." ".urlencode($r[10]));
          }
  }
  else
  {
    $Narration=$Narration." ".urlencode($r[10]);
            $ItemQty=$r[8];
        $ItemUnitPrice=$r[9];
        $NetAmount=$r[10];
        $ItemID=$r[12];
        $ItemID=getnamesingle("inventory","ID","Name","'".$ItemID."'",$connection);

  echo  $sql="insert into invoicedetail (InvoiceID,ItemID,UnitPrice,Qty,Amount,NetAmount,UnitID,,InvoiceDate,DueDate) values($InvoiceID,$ItemID,$ItemUnitPrice,$ItemQty,$NetAmount,$NetAmount,1,'$InvoiceDate','$DueDate')";
odbc_exec($connection, $sql) or die(odbc_error().$sql);
  }   
/*
        if($VID==$Reference && trim($VID)!="" )
        {
       // print_r($r);
        /*
        $VID=$r[3];//."<br>";
        $VoucherDate=trim($r[4]);//voucher date
        if($VoucherDate!="")
        {
          //  print_r($VoucherDate);
            $vd=explode("/",$VoucherDate);
            $temp=$vd[0];//day
            $mt=$vd[1];//month
            $yt=$vd[2];//Year

           // $VoucherDate=$yt."-".$mt."-".$temp;

        }

        $SupplierName=$r[1];        
        $LocationName=$r[2];        
        $DueDate=$r[5];
        $TotalAmount=$r[6];
        $NetAmount=$r[7];
        $PurchaseLedgerID=$r[8];
        $SupplierLedgerID=$r[9];
        $ItemName=$r[10];
        $ProductCode=$r[11];
        $ItemUnitPrice=$r[12];
        $ItemQty=$r[13];
        $ItemSubTotal=$r[14];
        $VatAmount=$r[15];
        $PurchaseOrderNo=$r[16];
        $Remarks=$r[17];//memo
        
        $PurchaseLedgerID=getnamesingle("Accounts","COAID","COANAME","'".$PurchaseLedgerID."' and [group]=0",$connection);
        $PurchaseLedgerID=($PurchaseLedgerID!="")?$PurchaseLedgerID:0;
        $SupplierLedgerID=getnamesingle("Accounts","COAID","COANAME","'".$SupplierLedgerID."' and [group]=0",$connection);
        $SupplierLedgerID=($SupplierLedgerID!="")?$SupplierLedgerID:0;

        $Debit=($r[6]!="")?$r[6]:0;
        $Credit=($r[6]!="")?$r[6]:0;
        $Remarks=$r[7];
        //$fdetails[$c]=$r;
        $fdetails['VoucherID']=$VoucherID;
        if($Debit>0)
        {
        $fdetails['LedgerID']=$PurchaseLedgerID;//$d->CustomerLedgerID; DEbit side entry
        $CreditLedgerID=$SupplierLedgerID;    
        }
        else
        {
        $fdetails['LedgerID']=$PurchaseLedgerID;//$d->CustomerLedgerID; DEbit side entry
        $CreditLedgerID=$SupplierLedgerID;    
        }
        
        $GodownID=3;
           $fdetails['Debit']=$Debit;
           $fdetails['Credit']=$Credit;
           $fdetails['Narration']=$Narration.$InvoiceRef;
           $fdetails['ReferenceInvoiceID']=0;
           $fdetails['CreditLedgerID']=$CreditLedgerID;
           $fdetails['CostCenterID']=$GodownID;//company
           $fdetails['ChequeNo']='';
           $fdetails['IsDelete']=0;
           $fdetails['DebitCostCenterID']=$GodownID;//company
           $fdetails['TransactionType']=$Remarks;   
           InsertVoucherDetail($fdetails,$InvoiceType,$VoucherID,$connection);      
           //print_r($fdetails);
        *///}
        /*
                else
                {

        //print_r($r);
        //$VID=$r[0];//."<br>";
        $VoucherDate=trim($r[1]);
        if($VoucherDate!="")
        {
            //print_r($VoucherDate);
            $vd=explode("/",$VoucherDate);
            $temp=$vd[0];//day
            $mt=$vd[1];//month
            $yt=$vd[2];//Year

        //    $VoucherDate=$yt."-".$mt."-".$temp;

        }

        $Narration=utf8_encode($r[2]);        
        $InvoiceRef=$r[3];        
        $LedgerName=$r[4];
        $LedgerID=getnamesingle("Accounts","COAID","COANAME","'".$LedgerName."'",$connection);
        $Debit=($r[5]!="")?$r[5]:0;
        $Credit=($r[6]!="")?$r[6]:0;
        $Remarks=$r[7];
        //$fdetails[$c]=$r;
        $fdetails['VoucherID']=$VoucherID;
        if($Debit>0)
        {
        $fdetails['LedgerID']=$LedgerID;//$d->CustomerLedgerID; DEbit side entry
            $CreditLedgerID=0;    
        }
        else
        {
            $fdetails['LedgerID']=0;//$d->CustomerLedgerID; DEbit side entry
            $CreditLedgerID=$LedgerID;    
        }
        
        
           $fdetails['Debit']=$Debit;
           $fdetails['Credit']=$Credit;
           $fdetails['Narration']=$Narration.$InvoiceRef;
           $fdetails['ReferenceInvoiceID']=0;
           $fdetails['CreditLedgerID']=$CreditLedgerID;
           $fdetails['CostCenterID']=3;//company
           $fdetails['DebitCostCenterID']=3;//company
           $fdetails['ChequeNo']='';
           $fdetails['IsDelete']=0;
          // $fdetails['DebitCostCenterID']=$GodownID;//company
           $fdetails['TransactionType']=$Narration;   
        //   print_r($fdetails);
        InsertVoucherDetail($fdetails,$InvoiceType,$VoucherID,$connection);      
                }*/




        if($r!="")
		$rows[] = array_combine( $header_values, $r );
        else
        $rows[] = array_combine( $header_values, "-" );
    $col++;
  /*if($k==12)
  break;  */
	}
    //print_r( $rows[] );
	//print_r( $rows );
/*
Array
(
    [0] => Array
        (
            [ISBN] => 618260307
            [title] => The Hobbit
            [author] => J. R. R. Tolkien
            [publisher] => Houghton Mifflin
            [ctry] => USA
        )

    [1] => Array
        (
            [ISBN] => 908606664
            [title] => Slinky Malinki
            [author] => Lynley Dodd
            [publisher] => Mallinson Rendel
            [ctry] => NZ
        )

)

for($x=0;$x<10000;$x++)
{

}*/
}

if ((!odbc_error()) && $isError==0)
   {
      odbc_commit($connection);
      $res=array('status'=>"ok",'description'=>'Data Saved Sucessfully');
     // echo "<script>alert('Purchase Voucher Saved Successfully');window.location='BookingUpload.php'</script>";
  }
else
{
      odbc_rollback($connection);
      $res=array('status'=>"Error",'description'=>'Record  Not Updated');
echo "<script>alert('Upload FAILED TRY AGAIN');window.location='BookingUpload.php'</script>";
}
/*unset($_FILES['file1']);//="";
      echo "<script>alert('Purchase Voucher Saved Successfully');window.location='purchaseupload.php'</script>";
*/
    //echo ($res); 
}//end file if
/*
<tr><td>Select Voucher Type </td><td><select name="VoucherType">
<option value="5">Receipt Voucher </option>
<option value="6">Payment Voucher </option>
<option value="7">Journal Voucher </option>
<option value="10">Petty Cash Voucher </option>
<option value="71">Purchase Voucher </option>
</select></td></tr>
*/
echo '<h2>Upload Purchase Voucher</h2>
<form method="post" enctype="multipart/form-data">
<table>
<tr>
<td>
*.XLSX <input type="file" name="file1"  /></td><td>
&nbsp;&nbsp;<input type="submit" value="Upload" name="Upload" /></td>
</tr>
</table>
</form>';
