<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* set A4 size */
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        @page {
            size: A4;
            margin: 0;
        }
        

        /* set content to fill the entire A4 page */

        html,
        .logo  {
            position: relative;
            width: 50px;
            
            margin-top: 16px;
            cursor: pointer;
            resize: 5px;
            display: inline;

        }

        .logo img {
            resize: 10px;
        }

        .church {
            
    align-items: center;
    margin-left: 120px;
    margin-bottom: 100px;
    margin-top: -90px;
    
    
        }

    .header {
    background-color: rgb(212, 209, 209);
   

    
}

        body {
            width: 210mm;
            height: 297mm;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        /* style content with shade background*/
        .content {
           
            /* adjust the width: ; */
            width: 80%;
            /* adjust the height */
            height: 80%;
            padding: 20px;
            box-sizing: border-box;
            background-color: #f0f0f0; /* light gray */
        }
        

    </style>
</head>
<body>

<?php

require 'databasebac.php';
$memberName = $_POST['memberName'];




// echo "Haha.. Connected successfully";
$sql = "SELECT * FROM `thites` WHERE `member` = '$memberName'";
$sql2 = "SELECT SUM(ThithesAmount) AS Total_Thithes FROM `thites` WHERE `member` = '$memberName'";

$results = mysqli_query($con, $sql);
$results2 = mysqli_query($con, $sql2);

// srtatement for all thites amount based on name
if ($results === false) {
  // code...
  echo mysqli_error($con);
} else {

//    
  // code...
  $viewThites= mysqli_fetch_all($results, MYSQLI_ASSOC );
  // read all amount from that name then sum them


  
}




// statement for total thites
// if ($results2->num_rows > 0) {
//     while($row = $results2->fetch_array()) {
//         $sum = $row['Total_Thithes'];
//         echo "$sum)";
//     }
//  }
//  else 
//     echo "no thites for this user";



$row = $results2->fetch_array();
$sum = $row['Total_Thithes'];
echo $sum;

?>

<?php if (empty($viewThites)):?>
         <p>No Amount found</p>
       <?php else: ?>
       
        
         <?php foreach ($viewThites as $thites):  ?>
           

           
       <?php endforeach; ?>
       <!-- </ul>
      <div class="total">
     <p class="total">The total is: <div class="sum"><p>$<?php echo $sum; ?></p></div><p> for the year</p>
        
     </div> <div>
        <a href="">print thites statement letter</a>
     </div> -->
     <?php endif; ?> 
<br>
     


    
    <div class="content">
        <header class="header">
            
    <div class="logo">
        <img src="../newjerusalemlogo.png" alt=""><span>
        <div class="church"><h2>New Jerusalem Haitin Baptist Church</h2> <h3><center> 1912 E 139th Ave,
         </h3></center><center>  Tampa, FL 33613
         </h3></center><center> 
         (813) 971-7828</h3></center></span> </div
    </div>
    
    </header>
       <div> Dear <?php echo $thites['member'] ; ?> <br /></div>

        <div>The amout of offering that we have received for this year from you is $<?php echo $sum; ?>  .
        While we are thanking you for being one of our valuable member, we also want you to know that
        we will always keep you in our prayer <br></div>
        Sincerly.

        <div>_____________________</div>                                              
        <div>Pasteur Claudet Saintil</div>
        

    </div>
    
    
</body>
</html>