<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
    <div class="table-responsive col-sm-12">
        <div class="form-group col-sm-12">  
            <?php
//            echo validation_errors();
            $message = $this->session->userdata('message');
            $this->session->unset_userdata('message');
            if ($message) {
                echo $message;
            }
            ?>
            <form action="<?php echo base_url(); ?>super_admin_student/pay_for_course/<?php echo $person_info->student_id ?>" method="post" name="duePaymentForm" enctype="multipart/form-data" >
                <!--Some Required Hidden Value -->
                <input type="hidden" name="payment_id" value="<?php echo $payment_information->payment_id; ?>">
                <input type="hidden" name="person_id" value="<?php echo $person_info->person_id; ?>">
                <input type="hidden" name="course_batch_id" value="<?php echo $person_info->batch_id; ?>">
                <input type="hidden" name="course_id" value="<?php echo $person_info->course_id; ?>">
                <br>
                <br>

                <div class="form-group col-sm-12" id="">
                    <div class="form-group col-sm-4">
                        <label for="invoice_number">Invoice No:</label>
                        <input class="form-control" type="text" name="invoice_number" value="<?php
                        if (set_value('invoice_number')) {
                            echo set_value('invoice_number');
                        } else {
                            echo $payment_information->invoice_number;
                        }
                        ?>">
                    </div>
                </div>

                <div class="form-group col-sm-12" id="">
                    <div class="form-group col-sm-4">
                        <label for="unit_price">Unit Price</label>
                        <div class="controls">
                            <input class="form-control" name="unit_price" id="unit_price" disabled value="<?php
                            if (set_value('unit_price')) {
                                echo set_value('unit_price');
                            } else {
                                echo $person_info->course_price;
                            }
                            ?>" >
                        </div>
                    </div>
                    <div class="form-group col-sm-4">
                        <label for="total_pay" style="color: green">Total Pay:</label>
                        <input class="form-control" type="text" name="total_pay" value="<?php echo $payment_information->total; ?>" disabled>
                        <input class="form-control" type="hidden" name="total_pay" value="<?php echo $payment_information->total; ?>" >
                    </div>

                    <div class="form-group col-sm-4">
                        <label for="due_amount" class="required">Due Amount:</label>
                        <input class="form-control" type="text" name="due_amount" id="due_amount" value="<?php echo $person_info->course_price - $payment_information->total; ?>" disabled>
                        <input class="form-control" type="hidden" name="due" id="due" value="<?php echo $person_info->course_price - $payment_information->total; ?>">
                    </div>

                    <div class="form-group col-sm-4">
                        <label for="total_price">Total Price</label>
                        <div class="controls">
                            <input class="form-control" name="total_price" id="total_price" value="<?php echo ($person_info->course_price * 1); ?>" >
                        </div>
                    </div>
                </div>

                <div class="form-group col-sm-12" id="">
                    <div class="form-group col-sm-4">
                        <label for="payment_name">Payment Name<span style="color: red">*</span></label>
                        <div class="controls">
                            <input class="form-control" name="payment_name" id="payment_name" value="<?php
                            if ($person_info) {
                                echo $person_info->person_first_name;
                            }
                            ?>">
                        </div>
                    </div>
                    <div class="required" id="payment_name_status"> <?php echo form_error('payment_name'); ?></div>
                </div>

                <div class="form-group col-sm-12" id="">
                    <div class="form-group col-sm-4">
                        <label for="payment_amount">Payment Amount<span style="color: red">*</span></label>
                        <div class="controls">
                            <input required  name="payment_amount" id="payment_amount" onblur="checkPaymentAmount();" value="<?php
                            if (set_value('payment_amount')) {
                                echo set_value('payment_amount');
                            }
                            ?>" class="form-control">
                        </div>
                        <div class="required" id="payment_status"><?php echo form_error('payment_amount'); ?></div>
                        <script>
                            function checkPaymentAmount() {
                                
                                totalPrice = document.getElementById('total_price').value;
                                dueAmount = document.getElementById('due').value;
                                paymentAmount = document.getElementById('payment_amount').value;
//                                alert(dueAmount);
                                if (paymentAmount > dueAmount) {
                                    document.getElementById('submit').disabled = true;
                                    document.getElementById('payment_status').innerHTML = 'Your Payment OverFlow';
                                } else {
                                    document.getElementById('payment_status').innerHTML = '';
                                    document.getElementById('submit').disabled = false;
                                }
                            }
                        </script>
                    </div>
                    <div class="form-group col-sm-4">
                        <label for="payment_method">Payment Method<span style="color: red">*</span></label>
                        <div class="controls">
                            <select class="form-control" name="payment_method" id="payment_method" onchange="manupulatePaymentForm();">
                                <option value="">select Payment Method</option>
                                <option value="1">Paypal</option>
                                <option value="2">Credit Card</option>
                                <option value="3">Account Pay</option>
                                <option value="4">bKash</option>
                                <option value="5">Hand Cash</option>
                            </select>
                        </div>

                        <div class="required" id="payment_method_status"><?php echo form_error('payment_method'); ?></div>
                        <script>

                            function manupulatePaymentForm() {
                                paymentMethod = document.getElementById('payment_method').value;

                                serverPage = '<?php echo base_url(); ?>super_admin_student/manupulate_payment_form/' + paymentMethod;
                                xmlhttp.open("GET", serverPage);
                                xmlhttp.onreadystatechange = function ()
                                {
                                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                                    {
                                        document.getElementById('payment_form').innerHTML = xmlhttp.responseText;
                                    }
                                }
                                xmlhttp.send(null);
                            }
                        </script>
                    </div>
                </div>

                <div class="" id="payment_form"></div>

                <div class="form-group col-sm-12" id="">
                    <div class="form-group col-sm-5">
                        <label for="paid_on">Payment On<span style="color: red">*</span></label>
                        <div class="controls">
                            <input class="form-control" type="date" name="paid_on" id="paid_on" value="<?php
                            if (set_value('paid_on')) {
                                echo set_value('paid_on');
                            }
                            ?>">
                        </div>
                        <div class="required" id="paid_on_status"><?php echo form_error('paid_on'); ?></div>
                    </div>
                    <div class="form-group col-sm-5">
                        <label for="due_date">Due Payment Date<span style="color: red">*</span></label>
                        <div class="controls">
                            <input class="form-control" type="date" name="due_date" id="due_date" value="<?php
                            if (set_value('due_date')) {
                                echo set_value('due_date');
                            } else {
                                echo $payment_information->due_date;
                            }
                            ?>">
                        </div>
                    </div>
                </div>

                <div class="form-group col-sm-12" id="">
                    <div class="form-group col-sm-6">
                        <label for="payment_description">Payment Description </label>
                        <textarea name="payment_description" class="form-control" ><?php echo set_value('payment_description'); ?></textarea>
                    </div>
                </div>

                <div class="checkbox col-sm-6">
                    <?php if ($person_info->person_id && $person_info->batch_id) { ?>
                        <button type="submit" id="submit" class="btn btn-default" onclick="checkAllField();">Submit</button>
                        <button type="reset" class="btn btn-default">Reset</button>
                    <?php } ?>

                    <script>
                        function checkAllField() {
//                                alert();
                            window.stop();
                        }
                    </script>
                </div>
            </form>
        </div>
    </div>
</div>