<?php
session_start();
include '../assets/constant/config.php';

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}
?>

<?php include('include/sidebar.php'); ?>
<!-- Top Bar End -->
<?php include('include/header.php'); ?>

<!--  connect author at mdkhairnar92@gmail.com  -->
<div class="page-content-wrapper ">

    <div class="container-fluid">

        <div class="row">
            <div class="col-sm-12">
                <div class="page-title-box">
                    <div class="btn-group float-right">
                        <a href="add_contribution.php" class="btn btn-primary mb-3">Add Contribution</a>
                    </div>
                    <h4 class="page-title">View Contribution</h4>
                </div>
            </div>
            <div class="clearfix"></div>
        </div>
        <!-- end page title end breadcrumb -->

        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">
                        <div class="table-responsive">

                            <table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap" style="border-collapse: collapse; border-spacing: 0; width: 100%;" enctype="multipart/form-data">
                                <thead>
                                    <tr>
                                        <th>SN</th>
                                        <th>Branch </th>
                                        <th>member</th>
                                        <th>Amount</th>
                                        <th>Batch</th>
                                         <th>Type</th>
                                        <th>Payment method</th>
                                        <th>Date</th>
                                        <th>Action</th>
                                    </tr>
                                </thead>
                                <tbody>

                                    <?php
                                     $stmt = $conn->prepare("SELECT * FROM `contribution`WHERE `delete_status`='0'");
                                    // $stmt = $conn->prepare("SELECT c.id,c.member, c.branch, c.date, cd.amount, cd.contribution_id, cd.batch, cd.contritype, cd.fund, c.paymentmethod FROM `contribution` c JOIN `contribution_details` cd ON c.id = cd.contribution_id WHERE c.delete_status = '0' AND cd.delete_status = '0'");
                                    $stmt->execute();
                                    $record = $stmt->fetchAll();
                                    $i = 1;
                                    foreach ($record as $key) { ?>


                                        <tr>

                                            <td><?php echo $i; ?></td>
                                            
                                            <td><?php echo $key['branch']; ?></td>
                                            <td><?php echo $key['member']; ?></td>
                                            <td><?php echo $key['amount']; ?></td>
                                            <td><?php echo $key['batch']; ?></td>
                                            <td><?php echo $key['contritype']; ?></td>

                                            <td><?php echo $key['paymentmethod']; ?></td>
                                            <td><?php echo $key['date']; ?></td>


                                            <td>
                                                

                                                

<?php if (in_array('delete_contribution',$userroles) || ($admin['role']==0))
                  { ?>
                                              <a href="#" class="btn btn-danger" onclick="return confirm('Are you sure you want to delete this item?') && delForm1(event, <?php echo $key['id'] ?>,'app/contribution_crud.php');"><i class="fa fa-trash-alt" aria-hidden="true"></i></a><?php }?>
                                            </td>
                                        </tr>
                                    <?php $i++;
                                    } ?>
                                </tbody>
                               

                            </table>

                       </div><!--end /tableresponsive-->
                    </div><!--end card-body-->
                </div><!--end card-->
            </div><!--end col-->


        </div><!--end row-->





    </div> <!-- Page content Wrapper -->

</div> <!-- content -->

<?php include('include/footer.php'); ?>
<!--  Author Name: Mayuri K. 
 for any PHP, Codeignitor or Laravel website or software development contact me at mayuri.infospace@gmail.com  -->

