<?php 
ob_start();
session_start();
include ("../_init.php");

$subscription_id= $_GET['subscription_id'];
$hash           = $_GET['hash'];


$list=db()->prepare("SELECT * FROM `customer_subscribe` WHERE `id`=?");
$list->execute([$subscription_id]);
$subscription=$list->fetch(PDO::FETCH_ASSOC);
if(!$subscription){
    exit('Invalid request');
}
elseif($hash!=md5($subscription['id'].'-'.$subscription['created_on'])){
    exit('Invalid hash');
}
$list=db()->prepare("SELECT * FROM `customers` WHERE `customer_id`=?");
$list->execute([$subscription['customer_id']]);
$customer=$list->fetch(PDO::FETCH_ASSOC);


$print_data=[
    'store_name'     => store('name'),
    'store_address'     => store('address'),
    'customer_name'     => $customer['customer_name'],
    'customer_code'     => $customer['customer_code'],
    'customer_mobile'   => $customer['customer_mobile'],
    'customer_address'  => $customer['customer_address'],
    'amount'            => $subscription['amount'],
    'start_date'        => date('d-m-Y',$subscription['start_date']),
    'end_date'          => date('d-m-Y',$subscription['end_date']),
    'created_on'        => date('d-m-Y h:i:s',$subscription['created_on'])
];
if(isset($_GET['json'])){
    header('Content-Type: application/json; charset=utf-8');
    echo json_encode($print_data);
    exit;
}



// Redirect, If user is not logged in
if (!is_loggedin()) {
    redirect(root_url() . '/index.php?redirect_to=' . url());
}

// Redirect, If User has not Read Permission
if (user_group_id() != 1 && !has_permission('access', 'read_customer')) {
    redirect(root_url() . '/'.ADMINDIRNAME.'/dashboard.php');
}

// Set Document Title
$document->setTitle('Subscription print');
    // Include Header and Footer
include "header.php";
include "left_sidebar.php";
    ?>
    
    <div class="content-wrapper">
    <section class="content-header">
        <h1>
        Subscription print
            <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 class="active">Subscription print</li>
        </ol>
    </section>
    <section class="content">
<style>
        #invoice-POS {
            box-shadow: 0 0 1in -0.25in rgba(0, 0, 0, 0.5);
            padding: 3mm;
            margin: 0 auto;
            width: 350px;
            background: #fff;
        }

        #invoice-POS ::selection {
            background: #f31544;
            color: #fff;
        }

        #invoice-POS ::moz-selection {
            background: #f31544;
            color: #fff;
        }

        #invoice-POS h1 {
            font-size: 1.5em;
            color: #222;
        }

        #invoice-POS h2 {
            font-size: 1em;
        }

        #invoice-POS h3 {
            font-size: 1.4em;
            font-weight: 300;
            line-height: 2em;
        }

        #invoice-POS p {
            font-size: 1em;
            color: #666;
            line-height: 1.2em;
        }

        #invoice-POS #top,
        #invoice-POS #mid,
        #invoice-POS #bot {
            /* Targets all id with 'col-' */
            border-bottom: 1px solid #eee;
        }

        #invoice-POS #mid {
            min-height: 80px;
        }

        #invoice-POS #bot {
            min-height: 50px;
        }

        #invoice-POS .info {
            display: block;
            margin-left: 0;
        }
        #invoice-POS .info h2{
            font-size: 20px;
            font-weight: 700;
        }

        #invoice-POS .title {
            float: right;
        }

        #invoice-POS .title p {
            text-align: right;
        }

        #invoice-POS table {
            width: 100%;
            border-collapse: collapse;
        }

        #invoice-POS .tabletitle {
            font-size: 1em;
            background: #eee;
        }

        #invoice-POS .service {
            border-bottom: 1px solid #eee;
        }

        #invoice-POS .item {
            width: 24mm;
        }

        #invoice-POS .itemtext {
            font-size: 1em;
        }

        #invoice-POS #legalcopy {
            margin-top: 3mm;
        }
    </style>

    <div id="invoice-POS">
        <center id="top">
            <div class="info">
                <h2><?php echo store('name'); ?></h2>
                <p><?php echo store('address'); ?></p>
            </div><!--End Info-->
        </center><!--End InvoiceTop-->

        <div id="mid">
            <div class="info">
                <h2>Customer Information</h2>
                <p>
                    Name : <?=$print_data['customer_name']?></br>
                    ID : <?=$print_data['customer_code']?></br>
                    Phone : <?=$print_data['customer_mobile']?></br>
                    Address : <?=$print_data['customer_address']?></br>
                </p>
            </div>
        </div><!--End Invoice Mid-->

        <div id="bot">
            <div id="table">
                <table>
                    <tr class="tabletitle">
                        <td class="item">
                            Service
                        </td>
                        <td style="text-align:center">
                            Duration
                        </td>
                    </tr>

                    <tr class="service">
                        <td class="tableitem">
                            <div class="itemtext"><strong>Home Service</strong></div>
                            <div class="itemtext">1. Free Delevery</div>
                            <div class="itemtext">2. Cleaning Service</div>
                            <div class="itemtext">3. Gas Stove Maintainance</div>
                        </td>
                        <td style="text-align:center">
                            <strong class="itemtext">Paid: <?=$print_data['amount']?> Tk</strong>
                            <div class="itemtext">
                            <?=$print_data['start_date']?> <br>
                                To <br>
                                <?=$print_data['end_date']?> <br>
                            </div>
                        </td>
                    </tr>

                </table>
            </div><!--End Table-->
        </div><!--End InvoiceBot-->
        <div class="office-copy">
            <div id="mid">
                <div class="info">
                    <div style="text-align:center">
                        <h2>Office Copy</h2>
                    </div>
                    <p>
                    Name : <?=$print_data['customer_name']?></br>
                    ID : <?=$print_data['customer_code']?></br>
                    Phone : <?=$print_data['customer_mobile']?></br>
                    Address : <?=$print_data['customer_address']?></br>
                    </p>
                </div>
            </div><!--End Invoice Mid-->
            <div id="bot">
                <div id="table">
                    <table>
                        <tr class="tabletitle">
                            <td class="item">
                                Service
                            </td>
                            <td style="text-align:center">
                                Duration
                            </td>
                        </tr>

                        <tr class="service">
                            <td class="tableitem">
                                <div class="itemtext"><strong>Home Service</strong></div>
                                <div class="itemtext">1. Free Delevery</div>
                                <div class="itemtext">2. Cleaning Service</div>
                                <div class="itemtext">3. Gas Stove Maintainance</div>
                            </td>
                            <td style="text-align:center">
                                <strong class="itemtext">Paid: <?=$print_data['amount']?> Tk</strong>
                                <div class="itemtext">
                                <?=$print_data['start_date']?> <br>
                                    To <br>
                                    <?=$print_data['end_date']?> <br>
                                </div>
                            </td>
                        </tr>

                    </table>
                </div><!--End Table-->
            </div><!--End InvoiceBot-->
        </div>
        
        <div style="text-align: center;margin-top: 10px">
        <a class="btn btn-info" href="subscription_print.php?subscription_id=<?=$subscription['id']?>&hash=<?=md5($subscription['id'].'-'.$subscription['created_on'])?>&type_subscription=1&android_print=1"><i class="fa fa-print"></i> Android Printer</a>
        </div>
    </div><!--End Invoice-->
</section>
</div>
    <?php
include "footer.php"; 
