<?php
$customer_id=intval($_GET['customer_id']);
$list=db()->prepare("SELECT * FROM `customer_subscribe` WHERE `customer_id`=".$customer_id);
$list->execute();
$subscribes=$list->fetchAll(PDO::FETCH_ASSOC);

$list=db()->prepare("SELECT * FROM `customers` WHERE `customer_id`=?");
$list->execute([$customer_id]);
$customer=$list->fetch(PDO::FETCH_ASSOC);


$subscribe_list=[];
        if(!empty($subscribes)){
            
            foreach($subscribes as $s){
                $data=[
                    'start_date'=>date('d-m-Y',$s['start_date']),
                    'end_date'=>date('d-m-Y',$s['end_date']),
                    'amount'=>(float)$s['amount'],
                    'created_on'=>date('d-m-Y h:i:s',$s['created_on'])
                ];
                if($last_end<$s['end_date']){
                    $last_end=$s['end_date'];
                }
                $subscribe_list[]=$data;
            }
        }

?>
<div class="content-wrapper">
    <section class="content-header">
        <h1>
        Subscription Bill History
            <small>
                <?php echo store('name'); ?>
            </small>
        </h1>
        <ol class="breadcrumb">
            <li>
                <a href="dashboard.php">
                    <i class="fa fa-dashboard"></i> 
                    <?php echo trans('text_dashboard'); ?>
                </a>
            </li>
            <li><a href="subscription_list.php">Subscription list</a></li>
            <li class="active">Subscription Bill History</li>
        </ol>
    </section>
    <!-- Content Header Start -->

    <!-- Content Start -->
    <section class="content">

        <?php if(DEMO) : ?>
            <div class="box">
                <div class="box-body">
                    <div class="alert alert-info mb-0">
                        <p><span class="fa fa-fw fa-info-circle"></span> <?php echo $demo_text; ?></p>
                    </div>
                </div>
            </div>
        <?php endif; ?>

        <div class="row">
            <div class="col-xs-12">
                <div class="box box-success">
                    <div class="box-header">
                        <div class="row mt2">
                            <div class="col-md-9">
                                <h3 class="box-title">
                                Customer Name: <span style="color: #00aaff;font-weight: 600"> <?=$customer['customer_name']?></span> | Customer ID:  <span style="color:rgb(0, 60, 255);font-weight: 600"> <?=$customer['customer_code']?></span>
                                </h3>
                            </div>
                            <div class="col-md-3 text-right">
                                <!-- <a class="btn btn-info" href=""><i class="fa fa-print"></i> Print</a> -->
                            </div>
                        </div>
                        <div>
                        </div>
                    </div>
                    <div class="box-body">
                        <div class="table-responsive">
                            <!-- Customer List Start -->
                            <table class="table table-bordered table-striped table-hover table-header-center" data-hide-colums="">
                                <thead>
                                    <tr class="bg-gray">
                                        <th class="w-5">SL</th>
                                        <th class="w-10">Service Start date</th>
                                        <th class="w-15">Service End date</th>
                                        <th class="w-15">Payment Date</th>
                                        <th class="w-10">Paid Amount</th>
                                        <th class="w-10">Print</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    $serial=1;
                                    foreach($subscribes as $s){
                                        ?>
                                        <tr>
                                        <td class="text-center"><?=$serial++?></td>
                                        <td class="text-center"><?=date('d-m-Y',$s['start_date'])?></td>
                                        <td class="text-center"><?=date('d-m-Y',$s['end_date'])?></td>
                                        <td class="text-center"><?=date('d-m-Y h:i:s',$s['created_on'])?></td>
                                        <td class="text-center"><?=$s['amount']?></td>
                                        <td class="text-center"><a class="btn btn-info" href="subscription_print.php?subscription_id=<?=$s['id']?>&hash=<?=md5($s['id'].'-'.$s['created_on'])?>"><i class="fa fa-eye"></i> View Invoice</a></td>
                                        </tr>
                                        <?php
                                    }
                                    ?>
                                </tbody>
                            </table> 
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>
<style>
    .table-header-center tr th{
        text-align: center;
    }
</style>