<link rel="stylesheet" href="<?php echo base_url(); ?>assets_admin/css/invoice.css">

<div class="wraper responsive-width">
    <main class="printdiv1" id="main">
        <div class="main-wrap">
            <div class="dashboard-cover">
                <button type="button" class="btn btn-success btn-sm btn-dark back_btn">Back</button>
                <div class="common-heading">
                    <h2>Transactions Details</h2>
                </div>
                <div class="invoice_wrap" id="printpage">
                    <div class="invoice_head" id="printableArea">
                        <div class="invoice_head_left">
                            Bill Details
                        </div>
                        <div class="invoice_right">
                            <p id="printSection"><img src="<?php echo base_url(); ?>assets_admin/images/print.png" /></p>
                            <a href="<?= base_url(); ?>admin/invoicedownload/<?= urlsafe_b64encode($invoice_data['studentId']) ?>/<?= urlsafe_b64encode($invoice_data['txn_id']) ?>"><i class="fas fa-download"></i></a>
                        </div>
                    </div>
                    <div class="invoice_top">
                        <div class="invoice_top_left">
                            <?php 
                            if(empty($school_info['color_logo'])) {
                                $logo_img=base_url().'common_assets/black_logo.png';
                            }
                            else if(file_exists('common_assets/'.$school_info['color_logo']))
                            {
                                $logo_img=base_url().'common_assets/'.$school_info['color_logo'];
                            }
                            else {
                                $logo_img=base_url().'common_assets/black_logo.png';
                            }
                            ?>
                            <img src="<?= $logo_img; ?>">
                        </div>
                        <div class="invoice_top_right">
                            <ul>

                                <li><label>Address </label>: <div><?= $school_info['address']; ?></div>
                                </li>
                                <li><label>Phone </label>: <div><?= $school_info['phone']; ?></div>
                                </li>
                                <li><label>Email </label>: <div><?= $school_info['email']; ?></div>
                                </li>
                                <li><label>Website </label>: <div><?= $school_info['website_link']; ?></div>
                                </li>
                                <li><label>School PAN </label>: <div><?= ($school_info['pan']) ? $school_info['pan'] : '-'; ?></div>
                                </li>

                            </ul>
                        </div>
                    </div>

                    <div class="invoice_content" >
                        <div class="invoice_content_left" style="width: 33.33%;">
                            <ul>
                                <li><label>Student Name </label>: &nbsp; <span><?= $invoice_data['studentname'] ?></span></li>
                                <li><label>Classroom </label>: &nbsp; <span>
                                        <?php
                                        $section_id = (!empty($invoice_data['section_id']) && isset($invoice_data['section_id'])) ? $invoice_data['section_id'] : 0;
                                        if ($section_id != 0)
                                            $section_name = $this->db->get_where('section', array('id' => $section_id))->row()->section_name;
                                        else
                                            $section_name = '';

                                        $course_name = $this->db->get_where('course', array('id' => $invoice_data['course_id']))->row()->course_name;
                                        echo (!empty($section_name)) ? $course_name . ' - ' . $section_name : $course_name;
                                        ?>
                                    </span></li>
                                <li><label>Student id </label>: &nbsp; <span><?= $invoice_data['studentId']; ?></span></li>
                                <li><label>Batch</label>: &nbsp; <span><?php echo $invoice_data['batch_name'];  ?></span></li>
                                
                            </ul>
                        </div>
                        <div class="invoice_content_right" style="width: 28.33%;">
                            <ul>
                                <li><label>Parent PAN </label>: &nbsp; <span><?php echo $invoice_data['batch_name'];  ?></span></li>
                                <li><label class="w-110">Transaction id </label>: &nbsp; <span><?= $invoice_data['txn_id'] ?></span></li>
                                <li><label class="w-110">Date </label>: &nbsp; <span><?= date('d-m-Y H:i:s', strtotime($invoice_data['paid_date'])) ?></span></li>

                                <li><label class="w-110">Billed By </label>:&nbsp;&nbsp;<span><?= $invoice_data['received_by'] ?></span></li>
                                
                            </ul>
                        </div>
                        <div class="invoice_content_right" style="width: 38.33%;">
                            <ul>
                                <li><label class="w-186">Bill Print Count </label>:&nbsp;&nbsp;<span class="bill_count"><?php echo $invoice_data['bill_print_count'] ?></span></li>
                                <li><label class="w-186">Mode of Payment </label>:&nbsp;&nbsp;<span><?= $invoice_data['payment_method'] ?></span></li>
                                <li><label class="w-186">Transaction Date and Time </label>:&nbsp;&nbsp;<span><?= $invoice_data['tdt'] ?></span></li>
                                <li><label style="width: 80px">Bill Number</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp; <span><?= $invoice_data['course_fee_id'].$invoice_data['studentId'].'/'.$invoice_data['install_sno'] ?></span></li>
                                
                            </ul>
                        </div>
                    </div>
                    <div class="invoice_table">
                        <table style="text-align: center;">
                            <thead>
                                <tr>
                                    <th>Sl No</th>
                                    <th>Description Fee</th>
                                    <th>Amount</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>1</td>
                                    <td><?= $invoice_data['payment_for'] ?></td>
                                    <td><?= $school_info['currency_symbol']; ?> <?= $invoice_data['payment_amt'] ?></td>
                                </tr>
                            </tbody>
                            <tfoot>
                                <!-- <tr>
                                    <td colspan="2" style="background-color: #ffff;">Total Estimate Cost :</td>
                                    <td style="background-color: #ffff;"><?= $invoice_data['payment_amt'] ?></td>
                                </tr> -->
                                 <tr style="background-color: #ffff;border: none;">
                                    <td colspan="2" style="background-color: #ffff;border: none;">Fine :</td>
                                    <td style="background-color: #ffff;border: none;"><?= $invoice_data['fine_amount'] ?></td>
                                </tr>
                                <tr style="background-color: #ffff;">
                                    <td colspan="2" style="background-color: #ffff;border: none;"><?= ucfirst($invoice_data['deduction_type']) ?> :</td>
                                    <td style="background-color: #ffff;border: none;"> <?= $invoice_data['deduction_amount'] ?></td>
                                </tr>
                                <tr>
                                    <td colspan="2" >Total Paid :</td>
                                    <td ><?= $school_info['currency_symbol']; ?> <?= (($invoice_data['payment_amt'] + $invoice_data['fine_amount'] ) - $invoice_data['deduction_amount']) ?></td>
                                </tr>
                                <tr>
                                    <td colspan="3" style="background-color: #ffff;">Amount In Word : &nbsp;&nbsp;<?php  echo '"'. amountInWords((($invoice_data['payment_amt'] + $invoice_data['fine_amount'] ) - $invoice_data['deduction_amount'])) .'"'; ?></td>
                                    
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                    <div class="invoice_footer">
                        <p>“This is computer generated receipt, no signature required.”</p>
                    </div>

                </div>
            </div>
        </div>
    </main>
</div>

<script type="text/javascript">
    // $("#printSection").on("click", function() {
    //     //alert($(window).height());
    //     var ht = $(window).height();
    //     var wt = $(window).width();
    //     var divContents = $("#printpage").html();
    //     var printWindow = window.open('', '', 'height=' + ht + 'px,width=' + wt + 'px');
    //     printWindow.document.write('<html><head><title>Invoice</title>');
    //     printWindow.document.write('<link rel="stylesheet" href="<?php echo base_url(); ?>assets_admin/css/invoice.css">');
    //     printWindow.document.write('</head><body>');
    //     printWindow.document.write(divContents);
    //     printWindow.document.write('</body></html>');
    //     printWindow.document.close();
    //     printWindow.print();
    // });

    $("#printSection").on("click", function() {
         var element = $(".bill_count").text();         
         $(".bill_count").text(parseInt(element)+1);
         $.ajax({
            url: "<?= base_url().'admin/printcount_increment'; ?>",
            method: "POST",
            data: {
                inoviceids: <?php echo $invoice_data['student_fee_online_transactions_id']; ?>
            },
            success: function(response) {
                console.log('done');
            } });

        var frame1 = $('<iframe />').attr("id", "printDiv");
        frame1[0].name = "frame1";
        frame1.css({"position": "absolute", "top": "-1000000px"});
        var divContents = $("#printpage").html();
        $("body").append(frame1);
        var frameDoc = frame1[0].contentWindow ? frame1[0].contentWindow : frame1[0].contentDocument.document ? frame1[0].contentDocument.document : frame1[0].contentDocument;
        frameDoc.document.open();
        //Create a new HTML document.
        frameDoc.document.write('<html>');
        frameDoc.document.write('<head>');
        frameDoc.document.write('<title></title>');

        // frameDoc.document.write('<link rel="stylesheet" href="<?php echo base_url(); ?>assets_admin/css/bootstrap.min.css">');
        frameDoc.document.write('<link rel="stylesheet" href="<?php echo base_url(); ?>assets_admin/css/invoice.css">');
        frameDoc.document.write('</head>');
        frameDoc.document.write('<body>');
        frameDoc.document.write(divContents);
        frameDoc.document.write('</body>');
        frameDoc.document.write('</html>');
        frameDoc.document.close();
        setTimeout(function () {
        document.getElementById('printDiv').contentWindow.focus();
        document.getElementById('printDiv').contentWindow.print();
            // frame1.remove();
            if (winload) {
                window.location.reload(true);
            }
        }, 500);


        return true;

    });


    $(document).ready(function(){
        $('.back_btn').click(function(){
            parent.history.back();
            return false;
        });
    });

</script>