<?php
 //export.php
 include "../actions/dbPDO.php";
 if(!empty($_FILES["excel_inn"]))
 {
      $file_array = explode(".", $_FILES["excel_inn"]["name"]);
      if($file_array[1] == "xls")
      {
           include("../op/PHPExcel/IOFactory.php");
          //  $reader = PHPExcel_IOFactory::createReader("Excel5");
           $object = PHPExcel_IOFactory::load($_FILES["excel_inn"]["tmp_name"]);
           foreach($object->getWorksheetIterator() as $worksheet)
           {
                $highestRow = $worksheet->getHighestRow();
                $row = 2; $segl = 1 ;
                while($row<=$highestRow)
                {
                     $contract_id     =  $worksheet->getCellByColumnAndRow(0, $row)->getValue();
                     $money_in        =  $worksheet->getCellByColumnAndRow(1, $row)->getValue();
         $maxsql= $db->prepare("SELECT max(in_id) as maxd FROM invoice");
         $maxsql->execute();
      if($maxsql->rowCount()>0){$result = $maxsql->fetch(PDO::FETCH_ASSOC);
                          $maxD = $result['maxd']+1;} else {$maxD = 1 ; }
        // $branch = intval($contract_id / 100000) + 1 ;
        $branch = 1 ;
        $sql = $db->prepare(" INSERT INTO invoice(in_id , contract_id  , money_in , branch )
                              VALUES (?, ?, ?, ?)" );
                       $sql->bindParam(1,$in_id);
                       $sql->bindParam(2,$contract_id);
                       $sql->bindParam(3,$money_in);
                       $sql->bindParam(4,$branch);
                       $sql->execute() ;
                    $segl = $segl + 1 ;
                    $row =  $row + 1 ;
                }
 }
 echo $segl;

 }
 }

 ?>
