

<?php 


include('../conn.php');


if(isset($_POST['submit'])){
 
  $filename = $_FILES['image']['name'];
     $supplier=$_POST['supplier'];
     $supplier_contact=$_POST['contact'];
     $receipt_date=$_POST['receipt_date'];
     $total=$_POST['total'];
     $datein=$_POST['datein'];
     $by=$_POST['by'];
     $receipt_id=$_POST['receipt_id'];
     $info=$_POST['info'];
   
    
		
 
     

     // Select file type
	$imageFileType = strtolower(pathinfo($filename,PATHINFO_EXTENSION));
	
	// valid file extensions
	$extensions_arr = array("jpg","jpeg","png");
 
	// Check extension
	if( in_array($imageFileType,$extensions_arr) ){
 
	// Upload files and store in database
	if(move_uploaded_file($_FILES["image"]["tmp_name"],'receipts/'.$filename)){

     $sql2 = "INSERT INTO `receipt`( `receipt_id`, `image`, `company`, `company_contact`, `info`, `total`, `by`, `receipt_date`, `date`) VALUES ('$receipt_id','$filename','$supplier','$supplier_contact','$info','$total','$by','$receipt_date','$datein')";
     if(mysqli_query($conn,$sql2)){
      $_SESSION['receipt_id']=$receipt_id;
   echo"<script>alert('Receipt successfully added. Add individual Items'); window.location.href='../add_inventory?re=$receipt_id'</script>";
     }
     else{
       echo 'Error: '.mysqli_error($conn);
     }
    }else{
      echo 'Error in uploading file - '.$_FILES['image']['name'].'<br/>';
    }

  }

}

?>
 