<?php
 //export.php
 include "../actions/dbPDO.php";
 if(!empty($_FILES["excel_nn"]))
 {
      $file_array = explode(".", $_FILES["excel_nn"]["name"]);
      if($file_array[1] == "xls")
      {
           include("../op/PHPExcel/IOFactory.php");
          //  $reader = PHPExcel_IOFactory::createReader("Excel5");
           $object = PHPExcel_IOFactory::load($_FILES["excel_nn"]["tmp_name"]);
           foreach($object->getWorksheetIterator() as $worksheet)
           {

                $highestRow = $worksheet->getHighestRow();
                $row = 1; $segl = 1 ;
                while($row<=$highestRow)
                {
                     $contract_id     =  $worksheet->getCellByColumnAndRow(0, $row)->getValue();
                     $money_in        =  $worksheet->getCellByColumnAndRow(1, $row)->getValue();
                     $sanad_date      =  $worksheet->getCellByColumnAndRow(2, $row)->getValue();

                     $sanad_date2    = date('Y-m-d', PHPExcel_Shared_Date::ExcelToPHP($sanad_date));

                     $payFor = "1"; $printed_no = "00"; $payMethod = "1" ; $comm = "إجمالي قبض البرنامج القديم ";
                     $father = "3"; $branch = "1";
                     $maxsql= $db->prepare("SELECT max(in_id) as maxd FROM invoice");
                     $maxsql->execute();
                     if($maxsql->rowCount()>0){$row = $maxsql->fetch(PDO::FETCH_ASSOC);
                       $maxD = $row['maxd']+1;} else {$maxD = 1 ; }

     $sanad=$db->prepare(" INSERT INTO invoice(in_id , contract_id , printed_no , sanad_date , money_in , payMethod ,
                       payFor , comm , father , branch  )
                   VALUES( ? , ? , ? , ? , ? , ? , ? ,?, ?, ? )");
                   $sanad->bindParam(1,$maxD);
                   $sanad->bindParam(2,$contract_id);
                   $sanad->bindParam(3,$printed_no);
                   $sanad->bindParam(4,$sanad_date2);
                   $sanad->bindParam(5,$money_in);
                   $sanad->bindParam(6,$payMethod);
                   $sanad->bindParam(7,$payFor);
                   $sanad->bindParam(8,$comm);
                   $sanad->bindParam(9,$father);
                   $sanad->bindParam(10,$branch);
                    $sanad->execute() ;
                    $segl = $segl + 1 ;
                    $row =  $row + 1 ;
                    }

 }
 echo $segl ;
 }
 }

 ?>
