403Webshell
Server IP : 210.245.233.93  /  Your IP : 216.73.216.226
Web Server : Apache/2.2.15 (CentOS)
System : Linux webserver2.onesolution.com.hk 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64
User : apache ( 48)
PHP Version : 5.3.3
Disable Function : exec, shell_exec, system, passthru, popen, proc_open, pcntl_exec
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/(Del)pathways.org.hk/MIS20140127/old20140407/student_invoice/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/(Del)pathways.org.hk/MIS20140127/old20140407/student_invoice/invoice_edit.php
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <?php
        require_once '../include/head.php';
        require_once '../include/checkuser.php';
        require_once '../include/Nav_bar.php';
        include_once '../include/DBConnect.php';
        require_once '../include/Classes/PHPExcel.php';
        require_once '../include/Classes/PHPExcel/IOFactory.php';
        require_once '../include/Classes/PHPExcel/Writer/Excel2007.php';

        if (isset($_POST['Export']) && $_POST['Export'] == 'Export to Excel') {
            //echo '<script>alert("GGGGGGGGGG")</script>';
            $invoice_id = $_POST['invoice_id'];
            $root_id = $_POST['root_id']; //this is root id , wrong naming
            $invoice_date = $_POST['invoice_date'];
            $event_code = $_POST['event_code'];
            $total_price = $_POST['total_price'];
            $total_discount = $_POST['total_discount'];
            $total_amount = $_POST['total_amount'];
            $invoice_code = $_POST['invoice_code'];

            $bill_to = $_POST['bill_to'];
            $prog_sub = $_POST['prog_sub'];
            $temp_prog_sub = explode('-', $prog_sub);
            $program = $temp_prog_sub[0];
            $subject = $temp_prog_sub[1];

            $PHPExcel = new PHPExcel();
            $reader = PHPExcel_IOFactory::createReader('Excel2007');
            $PHPExcel = $reader->load("../include/Classes/in-house_invoice.xls"); // sample is your file name 

            $PHPExcel->setActiveSheetIndex(0);
            $PHPExcel->getActiveSheet()->setCellValue('A5', $bill_to);
            $PHPExcel->getActiveSheet()->setCellValue('G4', $invoice_date);
            $PHPExcel->getActiveSheet()->setCellValue('G5', $invoice_code); //place a invoice_code here
            $PHPExcel->getActiveSheet()->setCellValue('G5', $event_code);
            $PHPExcel->getActiveSheet()->setCellValue('A7', $program); //program
            $PHPExcel->getActiveSheet()->setCellValue('B7', $subject); //subject

            $PHPExcelWriter = PHPExcel_IOFactory::createWriter($PHPExcel, 'Excel5');
            $PHPExcelWriter->save($invoice_code . '.xls');
            @header("Content-type: application/force-download");
            @header("Content-Disposition: attachment; filename=\"$invoice_code.'.xls'\"");
            @header("Content-Length: " . filesize($invoice_code . '.xls'));
        }

        if (isset($_POST['edit']) && $_POST['edit'] == 'Save') {
            $invoice_id = $_POST['invoice_id'];
            $root_id = $_POST['root_id']; //this is root id , wrong naming
            $invoice_date = $_POST['invoice_date'];
            $event_code = $_POST['event_code'];
            $total_price = $_POST['total_price'];
            $total_discount = $_POST['total_discount'];
            $total_amount = $_POST['total_amount'];
            $invoice_code = $_POST['invoice_code'];
            //invoice data 

            $query_get_i_root_id = "Select root_id from invoice where invoice_id='$invoice_id' and deleted=0";
            $result_get_i_root_id = $dbh->query($query_get_i_root_id);
            $result_get_i_root_id->setFetchMode(PDO::FETCH_OBJ);
            $invoice_root_id = $result_get_i_root_id->fetch()->root_id;

            $query = "Update invoice set deleted=1 where invoice_id='$invoice_id'";
            $result = $dbh->query($query);
            $query1 = "Update invoice_line set deleted=1 where invoice_id='$invoice_id'";
            $result1 = $dbh->query($query1);

            $query = "Insert into invoice set invoice_code='$invoice_code',root_id='$invoice_root_id',createby=0,createdate=Now(),lastupby=0,lastupdate=Now(),actived=1,deleted=0,
                stu_linking_id='$root_id',event_code='$event_code',invoice_date='$invoice_date',total_original_fee='$total_price',
                    total_discount_fee='$total_discount',total_amount='$total_amount'";
            $result = $dbh->query($query);
            if (!$result) {
                echo '<script>alert("Error1 .")</script>';
            }
            $query_get_invoice_id = "Select Max(invoice_id) as i_id from invoice where stu_linking_id='$root_id' and event_code='$event_code'  and deleted=0";
            $result_get_invoice_id = $dbh->query($query_get_invoice_id);
            $result_get_invoice_id->setFetchMode(PDO::FETCH_OBJ);
            $invoice_id = $result_get_invoice_id->fetch()->i_id;

            //insert invoice here
            if (isset($_POST['activity_id'])) {
                for ($j = 0; $j < count($_POST['activity_id']); $j++) {
                    $activity_id = $_POST['activity_id'][$j];
                    $fee_type = $_POST['fee_type'][$j];
                    $price = $_POST['price'][$j];
                    $attendance = $_POST['attendance'][$j];
                    $discount = $_POST['discount'][$j];
                    $amount = $_POST['amount'][$j];
                    $hr = $_POST['hours'][$j];
                    if (isset($_POST['is_charge'][$j]))
                        $is_charge = 0;
                    else
                        $is_charge = 1;
                    $type = $_POST['type'][$j];
                    $type_rate = $_POST['type_rate'][$j];
                    if ($type == 1) {
                        $query1 = "Insert into invoice_line set createby=0,createdate=Now(),lastupby=0,lastupdate=Now(),
        actived=1,deleted=0,invoice_id='$invoice_id',activity_id='$activity_id',event_programme_fee_type='$fee_type',
        discount_type='$type',original_fee='$price',discounted_fee='$discount',amount='$amount',
        hour='$hr',subsidy_percent='$type_rate',is_charge='$is_charge',remarks=''";
                    } else {
                        $query1 = "Insert into invoice_line set createby=0,createdate=Now(),lastupby=0,lastupdate=Now(),
        actived=1,deleted=0,invoice_id='$invoice_id',lesson_id='$lesson_id',event_programme_fee_type='$fee_type',
        discount_type='$type',original_fee='$price',discounted_fee='$discount',amount='$amount',
        hour='$hr',subsidy_percent='0',is_charge='$is_charge',remarks=''";
                    }
                    $result1 = $dbh->query($query1);
                    if (!$result1) {
                        echo '<script>alert("Error1 .")</script>';
                    }
                    $query2 = "Update activity_stu_list set invoice_gened=1 where activity_id='$activity_id' 
        and stu_linking_id='$root_id'";
                    $result2 = $dbh->query($query2);
                    if (!$result2) {
                        echo '<script>alert("Error2 .")</script>';
                    }
                }
            }
            if(isset($_POST['activity_id'])){
                $no_of_act=count($_POST['activity_id']);
            }
            else{
                $no_of_act=0;
            }
            $i = $_POST['i'];
            $i-=$no_of_act;
            for ($j = 0; $j < $i; $j++) {
                $lesson_id = $_POST['lesson_id'][$j];
                $attendance = $_POST['attendance'][$j];
                $fee_type = $_POST['fee_type'][$j];
                $j+=$no_of_act;
                $price = $_POST['price'][$j];
                $discount = $_POST['discount'][$j];
                $amount = $_POST['amount'][$j];
                $hr = $_POST['hours'][$j];
                if (isset($_POST['is_charge'][$j]))
                    $is_charge = 0;
                else
                    $is_charge = 1;
                $type = $_POST['type'][$j];
                $type_rate = $_POST['type_rate'][$j];
                if ($type == 1) {
                    $query1 = "Insert into invoice_line set createby=0,createdate=Now(),lastupby=0,lastupdate=Now(),
        actived=1,deleted=0,invoice_id='$invoice_id',lesson_id='$lesson_id',event_programme_fee_type='$fee_type',
        discount_type='$type',original_fee='$price',discounted_fee='$discount',amount='$amount',
        hour='$hr',subsidy_percent='$type_rate',is_charge='$is_charge',remarks=''";
                } else {
                    $query1 = "Insert into invoice_line set createby=0,createdate=Now(),lastupby=0,lastupdate=Now(),
        actived=1,deleted=0,invoice_id='$invoice_id',lesson_id='$lesson_id',event_programme_fee_type='$fee_type',
        discount_type='$type',original_fee='$price',discounted_fee='$discount',amount='$amount',
        hour='$hr',subsidy_percent='0',is_charge='$is_charge',remarks=''";
                }
                $result1 = $dbh->query($query1);
                if (!$result1) {
                    echo '<script>alert("Error1 .")</script>';
                }
                $query2 = "Update lesson_attendance set invoice_gened=1 where lesson_id='$lesson_id' 
        and stu_linking_id='$root_id'";
                $result2 = $dbh->query($query2);
                if (!$result2) {
                    echo '<script>alert("Error2 .")</script>';
                }
                $j-=$no_of_act;
            }

            echo '<script>alert("Edit invoice successful.")</script>';
            echo("<script>location.href ='invoice.php';</script>");
        }

        if (isset($_POST['edit1']) && $_POST['edit1'] == 'Save') {
            //$root_id = $_POST['root_id']; //this is root id
            $invoice_id = $_POST['invoice_id']; //old one
            $sch_id = $_POST['sch_id'];
            $invoice_date = $_POST['invoice_date'];
            $event_code = $_POST['event_code'];
            $total_price = $_POST['total_price'];
            $total_discount = $_POST['total_discount'];
            $total_amount = $_POST['total_amount'];
            $funding_type = $_POST['funding_type'];
            $desc = $_POST['desc']; //a statement of total hour
            $invoice_code = $_POST['invoice_code'];

            $query_get_i_root_id = "Select root_id from invoice where invoice_id='$invoice_id' and deleted=0";
            $result_get_i_root_id = $dbh->query($query_get_i_root_id);
            $result_get_i_root_id->setFetchMode(PDO::FETCH_OBJ);
            $invoice_root_id = $result_get_i_root_id->fetch()->root_id;
            $query = "Update invoice set deleted=1 where invoice_id='$invoice_id'";
            $result = $dbh->query($query);
            $query1 = "Update invoice_line set deleted=1 where invoice_id='$invoice_id'";
            $result1 = $dbh->query($query1);

            $query = "Insert into invoice set invoice_code='$invoice_code',root_id='$invoice_root_id',createby=0,createdate=Now(),lastupby=0,lastupdate=Now(),actived=1,deleted=0,
                school_id='$sch_id',event_code='$event_code',invoice_date='$invoice_date',funding_type='$funding_type',total_original_fee='$total_price',
                    total_discount_fee='$total_discount',total_amount='$total_amount',description='$desc'";
            $result = $dbh->query($query);
            if (!$result) {
                echo '<script>alert("Error2.1 .")</script>';
            }
            $query_get_invoice_id = "Select Max(invoice_id) as i_id from invoice where school_id='$sch_id' and event_code='$event_code' and deleted=0";
            $result_get_invoice_id = $dbh->query($query_get_invoice_id);
            $result_get_invoice_id->setFetchMode(PDO::FETCH_OBJ);
            $invoice_id = $result_get_invoice_id->fetch()->i_id;

            if (isset($_POST['activity_id'])) {
                for ($j = 0; $j < count($_POST['activity_id']); $j++) {
                    $activity_id = $_POST['activity_id'][$j];
                    //$price = $_POST['price'][$j];
                    //$discount = $_POST['discount'][$j];
                    $amount = $_POST['amount'][$j];
                    $hr = $_POST['hours'][$j];
                    if (isset($_POST['is_charge'][$j]))
                        $is_charge = 0;
                    else
                        $is_charge = 1;
                    $query1 = "Insert into invoice_line set createby=0,createdate=Now(),lastupby=0,lastupdate=Now(),
                    actived=1,deleted=0,invoice_id='$invoice_id',activity_id='$activity_id',amount='$amount',
                        hour='$hr',subsidy_percent='0',is_charge='$is_charge',remarks=''";

                    $result1 = $dbh->query($query1);
                    if (!$result1) {
                        echo '<script>alert("Error1 .")</script>';
                    }

                    $query2 = "Update activity_stu_list set invoice_gened=1 where activity_id='$activity_id' 
                    and deleted=0";
                    $result2 = $dbh->query($query2);
                    if (!$result2) {
                        echo '<script>alert("Error2 .")</script>';
                    }
                }
            }
            if(isset($_POST['activity_id'])){
                $no_of_act=count($_POST['activity_id']);
            }
            else{
                $no_of_act=0;
            }
            $i = $_POST['i'];
            $i-=$no_of_act;
            for ($j = 0; $j < $i; $j++) {
                $lesson_id = $_POST['lesson_id'][$j];
                $j+=$no_of_act;
                $amount = $_POST['amount'][$j];
                $hr = $_POST['hours'][$j];
                if (isset($_POST['is_charge'][$j])) {
                    $is_charge = 0;
                } else {
                    $is_charge = 1;
                }
                $query1 = "Insert into invoice_line set createby=0,createdate=Now(),lastupby=0,lastupdate=Now(),
                    actived=1,deleted=0,invoice_id='$invoice_id',lesson_id='$lesson_id',amount='$amount',
                        hour='$hr',subsidy_percent='0',is_charge='$is_charge',remarks=''";

                $result1 = $dbh->query($query1);
                if (!$result1) {
                    echo '<script>alert("Error1 .")</script>';
                }

                $query2 = "Update lesson_attendance set invoice_gened=1 where lesson_id='$lesson_id' 
                    and deleted=0";
                $result2 = $dbh->query($query2);

                if (!$result2) {
                    echo '<script>alert("Error2 .")</script>';
                }
                $j-=$no_of_act;
            }

            echo '<script>alert("Edit invoice successful.")</script>';
            echo("<script>location.href ='invoice.php';</script>");
        }
        if (isset($_POST['Export1']) && $_POST['Export1'] == 'Export to Excel') {
            
        }
        ?>
        <script>
            function cal_total() {
                var i = $('#i').val();
                var total_amount = 0;
                for (var j = 0; j < i; j++) {
                    //var obj=getElementById('lesson_'+j);
                    //if (obj.checked) {
                    var temp_amount = parseFloat($('#amount_' + j).val());
                    total_amount += temp_amount;
                    //}
                }
                $('#total_amount').val(total_amount);
            }
            ;
            function cal_discount() {
                var i = $('#i').val();
                var total_discount = 0;
                for (var j = 0; j < i; j++) {
                    //var obj=getElementById('lesson_'+j);
                    //if (obj.checked) {
                    var temp_discount = parseFloat($('#discount_' + j).val());
                    total_discount += temp_discount;
                    //}
                }
                $('#total_discount').val(total_discount);
            }
            ;
            $(function() {
                $('.date-picker').datetimepicker({pickTime: false, format: 'yyyy-MM-dd'});
            });
            function change_discount(obj) {
                //alert(obj.id);
                var target_id = obj.id;
                var target_i = target_id.split('_')[1];

                $.ajax({
                    type: "POST",
                    url: "ajax_invoice.php",
                    data: {
                        type: $('#type_' + target_i).val(),
                        linking_id: $('#linking_id').val()
                    },
                    cache: false,
                    success: function(html) {
                        if ($('#type_' + target_i).val() == 1) {//subsidy
                            $('#typerate_' + target_i).val(html);
                            var fee = $('#price_' + target_i).val() * (1 - (html / 100));//fee=amount wrong naming in the very first beginning
                            var discount = $('#price_' + target_i).val() * ((html / 100));
                            $('#amount_' + target_i).val(fee);
                            $('#discount_' + target_i).val(discount);
                            $('#typerate_' + target_i).attr("readonly", true);
                            cal_total();
                            cal_discount();
                        }
                        else {
                            if ($('#type_' + target_i).val() == 2) {//package_discount
                                $('#typerate_' + target_i).val(html);
                                $('#discount_' + target_i).val(html);
                                var fee = $('#price_' + target_i).val() - html;
                                $('#amount_' + target_i).val(fee);
                                $('#typerate_' + target_i).attr("readonly", true);
                                cal_total();
                                cal_discount();
                            }
                        }
                    }
                });
            }
            function in_sch_change_amount(obj) {
                var target_id = obj.id;
                var target_i = target_id.split('_')[1];
                var fee = $('#temp_' + target_i).val();//fee=amount wrong naming in the very first beginning
                fee = parseFloat(fee);
                $('#amount_' + target_i).val(fee);
                cal_total();
            }
            function not_charge(obj) {
                var target_id = obj.id;
                var target_i = target_id.split('_')[1];
                if (obj.checked) {
                    $('#typerate_' + target_i).val(0);
                    $('#discount_' + target_i).val(0);
                    $('#amount_' + target_i).val(0);
                    $('#type_' + target_i).attr('disabled', true);
                    cal_total();
                    cal_discount();
                }
                else {
                    change_discount(obj);
                    $('#type_' + target_i).attr('disabled', false);
                }
            }
            ;
            function in_school_not_charge(obj) {
                var target_id = obj.id;
                var target_i = target_id.split('_')[1];
                if (obj.checked) {
                    $('#amount_' + target_i).val(0);
                    cal_total();
                }
                else {
                    in_sch_change_amount(obj);
                    cal_total();
                }
            }
            ;
            function funding(obj) {
                var target_id = obj.id;
                var target_i = target_id.split('_')[1];
                var type_rate = $('#typerate_' + target_i).val();
                var price = $('#price_' + target_i).val();
                var fee = price - type_rate;//typerate_
                $('#discount_' + target_i).val(type_rate);
                $('#amount_' + target_i).val(fee);
                cal_total();
                cal_discount();
            }
            ;
            function selected(obj) {
                var target_id = obj.id;
                var target_i = target_id.split('_')[1];
                if (obj.checked == true) {
                    if ($('#is_charge_' + target_i).checked == false) {
                        $('#type_' + target_i).attr('disabled', false);
                        $('#charge_' + target_i).attr('disabled', false);
                        change_discount(obj);
                        cal_total();
                        cal_discount();
                    }
                    else {
                        $('#type_' + target_i).attr('disabled', true);
                        $('#charge_' + target_i).attr('disabled', false);
                        $('#discount_' + target_i).val(0);
                        $('#amount_' + target_i).val(0);
                        cal_total();
                        cal_discount();
                    }
                }
                else {
                    $('#type_' + target_i).attr('disabled', true);
                    $('#charge_' + target_i).attr('disabled', true);
                    $('#discount_' + target_i).val(0);
                    $('#amount_' + target_i).val(0);
                    cal_total();
                    cal_discount();
                }
            }
        </script>
    </head>
    <body>
        <!-- line between nav bar and content -->
        <div class="text-right">
            <ul class="breadcrumb">
                <li class="active">Invoice record</li>
            </ul>
        </div>
        <div class="container-fluid pathways-container">
            <?php
            $action = $_GET['action'];
            if ($action == "View") {
                if (isset($_GET['stu_root_id'])) {
                    $root_id = $_GET['stu_root_id'];
                    $invoice_id = $_GET['invoice_id'];
                    $linking_id = $_GET['linking_id'];
                    ?>
                    <form action="" method="POST" class="form-inline">
                        <input type="hidden" name="linking_id" id="linking_id" value="<?= $linking_id ?>">
                        <table border="0" class="table table-striped table-bordered table-hover table-condensed" width="100%">
                            <?php
                            $query = "Select i.invoice_code,i.funding_type,i.invoice_date,i.event_code,i.total_original_fee,i.total_discount_fee,
                                i.total_amount,sub.sub_name,prog.program_name,e.school_id,stu.linking_id,stu.last_name,stu.first_name from invoice as i,
                                student as stu,subject as sub,program as prog,event as e where i.event_code=e.event_code
                                 and e.program_id=prog.program_id and e.subject_id=sub.subject_id and i.stu_linking_id=stu.root_id
                                  and i.stu_linking_id='$root_id' and i.deleted=0 and i.actived=1 group by i.invoice_code";
                            $result1 = $dbh->query($query); //get invoice data
                            $result1->setFetchMode(PDO::FETCH_OBJ);
                            $row1 = $result1->fetch();
                            $total_price = 0;
                            $total_discount = 0;
                            $total_amount = 0;
                            $i = 0;
                            if ($row1->school_id == 0) {
                                ?>
                                <tr>
                                    <td colspan="14"><center><h3>INVOICE</h3></center></td>
                                </tr>
                                <tr>
                                    <td colspan="3">Bill To:</td>
                                    <td colspan="3">
                                        <input type="text" name="bill_to" required="true" value="<?= $row1->last_name . ' ' . $row1->first_name ?>" readonly="true">
                                        <input type="hidden" name="root_id" id="root_id" value="<?= $root_id ?>">
                                        <input type="hidden" name="linking_id" id="linking_id" value="<?= $linking_id ?>">
                                        <input type="hidden" name="invoice_id" id="invoice_id" value="<?= $invoice_id ?>">
                                    </td>
                                    <td colspan="2">Invoice Date:</td>
                                    <td colspan="5">
                                        <input type="text" name="invoice_date" class="" required='true' value="<?= $row1->invoice_date ?>" readonly="true">
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="3">Program-Subject</td>
                                    <td colspan="3"><input type="text" name="prog_sub" value="<?= $row1->program_name . '-' . $row1->sub_name ?>" readonly="true"></td>
                                    <td colspan="2">Invoice Code:</td>
                                    <td colspan="5"><input type="text" name="invoice_code" value="<?= $row1->invoice_code ?>" readonly="true"></td>
                                </tr>
                                <tr>
                                    <td colspan="3">Funding Type</td>
                                    <td colspan="3">
                                        <select name="funding_type" disabled="true">
                                            <option value="0">No Funding</option>
                                            <?php
                                            $query_funding = "Select funding_id,funding_type from funding where deleted=0 and actived=1";
                                            $result_funding = $dbh->query($query_funding);
                                            $result_funding->setFetchMode(PDO::FETCH_OBJ);
                                            while ($row_funding = $result_funding->fetch()) {
                                                if ($row_funding->funding_id == $row1->funding_type) {
                                                    ?>
                                                    <option value="<?= $row_funding->funding_id ?>" selected><?= $row_funding->funding_type ?></option>
                                                    <?php
                                                } else {
                                                    ?>
                                                    <option value="<?= $row_funding->funding_id ?>"><?= $row_funding->funding_type ?></option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </select>
                                    </td>
                                    <td colspan="2">Event Code:</td>
                                    <td colspan="5"><input type="text" name="event_code" value="<?= $row1->event_code ?>" readonly="true"></td>
                                </tr>
                                <tr>
                                    <th>Date</th>
                                    <th>Time from</th>
                                    <th>Time to</th>
                                    <th>Hour(s)</th>
                                    <th>Fee type</th>
                                    <th>Price($)</th>
                                    <th>Attendance</th>
                                    <th>Subsidy(%)/Package discount($)</th>
                                    <th>&nbsp;</th>
                                    <th>Discount($)</th>
                                    <th>Not Charge?</th>
                                    <th>Amount($)</th>
                                </tr>
                                <?php
                            }
                            $query_get_activity = "Select DATE_FORMAT(act.date, '%W') as weekday,act.date,il.activity_id,il.event_programme_fee_type,il.discount_type,il.original_fee,il.discounted_fee,il.amount,il.hour,
                            il.subsidy_percent,il.is_charge,act.start_time,act.end_time from activity as act,activity_stu_list as act_stu,invoice_line as il,event as e ,
                            invoice as i where act.event_id=e.event_id and i.event_code=e.event_code and
                            i.invoice_id=il.invoice_id and il.invoice_id='$invoice_id' and i.stu_linking_id='$root_id' and il.activity_id<>''
                             and il.deleted=0 and il.actived=1 and act.deleted=0 and act.actived=1 and act_stu.deleted=0 and i.deleted=0 group by il.activity_id";
                            $result_get_activity = $dbh->query($query_get_activity);
                            $result_get_activity->setFetchMode(PDO::FETCH_OBJ);
                            while ($row_activity = $result_get_activity->fetch()) {
                                $hour = round($row_activity->hour, 2);
                                $price = $row_activity->original_fee;
                                $amount = $row_activity->amount;
                                $discount = $row_activity->discounted_fee;
                                $total_price +=$price;
                                $total_discount +=$discount;
                                $total_amount +=$amount;
                                ?>
                                <tr>
                                    <td><input type="hidden" name="activity_id[]" id="activity_<?= $i ?>" value="<?= $row_activity->activity_id ?>" checked onclick="//selected(this);">
                                        <?= $row_activity->date . '(' . $row_activity->weekday . ')' ?><input type="hidden" name="date[]" value="<?= $row_activity->date ?>"></td>
                                    <td><?= $row_activity->start_time ?><input type="hidden" name="start_time[]" value="<?= $row_activity->start_time ?>"></td>
                                    <td><?= $row_activity->end_time ?><input type="hidden" name="end_time[]" value="<?= $row_activity->end_time ?>"></td>
                                    <td><?= $hour ?><input type="hidden" name="hours[]" value="<?= $hour ?>"></td>
                                    <td>Assessment/Test</td>
                                    <td><?= $price ?><input type="hidden" name="price[]" id='price_<?= $i ?>' value="<?= $price ?>"></td>
                                    <td>/</td><!--attendance-->
                                    <td>
                                        <?php
                                        if ($row_activity->discount_type == 1) {
                                            ?>
                                            <select name="type[]" style="width:100%;" id="type_<?= $i ?>" onchange="change_discount(this);" disabled="true">
                                                <option value="1" selected>Subsidy</option>
                                                <option value="2">Package discount</option>
                                                <!--<option value="3">Funding</option>-->
                                            </select>
                                        </td>

                                        <td><input type="number" style="width:60px;" name="type_rate[]" id="typerate_<?= $i ?>" value="<?= $row_activity->subsidy_percent ?>" readonly='true' onblur="funding(this);"></td>
                                        <?php
                                    } else {
                                        if ($row_activity->discount_type == 2) {
                                            ?>
                                        <select name="type[]" style="width:100%;" id="type_<?= $i ?>" onchange="change_discount(this);" disabled="true">
                                            <option value="1">Subsidy</option>
                                            <option value="2" selected>Package discount</option>
                                            <!--<option value="3">Funding</option>-->
                                        </select>
                                        </td>

                                        <td><input type="number" style="width:60px;" name="type_rate[]" id="typerate_<?= $i ?>" value="<?= $row_activity->discounted_fee ?>" readonly='true' onblur="funding(this);"></td>
                                        <?php
                                    }
                                }
                                ?>
                                <td><input type="number" style="width:90%;" name="discount[]" id="discount_<?= $i ?>" value="<?= $discount ?>" readonly='true'></td>

                                <?php if ($row_activity->is_charge == 1) { ?>
                                    <td><input type="checkbox" name="is_charge[]" id="charge_<?= $i ?>" onclick="not_charge(this);" value="1" disabled="true"></td>
                                    <?php
                                } else {
                                    ?>
                                    <td><input type="checkbox" name="is_charge[]" id="charge_<?= $i ?>" onclick="not_charge(this);" value="1" disabled="true" checked></td>
                                    <?php
                                }
                                ?>

                                <td><input type="text" style="width:90%;" name="amount[]" id='amount_<?= $i ?>' value="<?= $amount ?>" readonly="true"></td>
                                </tr>
                                <?php
                                $i++;
                            }
                            //get activity
                            $query1 = "Select DATE_FORMAT(l.date, '%W') as weekday,il.lesson_id,il.event_programme_fee_type,il.discount_type,il.original_fee,il.discounted_fee,il.amount,il.hour,
                            il.subsidy_percent,il.is_charge,il.remarks,l.date,l.start_time,l.end_time,la.attendance from invoice_line as il,
                            lesson as l,lesson_attendance as la,invoice as i where il.lesson_id=l.lesson_id and la.lesson_id=il.lesson_id and 
                            la.stu_linking_id=i.stu_linking_id and i.invoice_id=il.invoice_id and il.invoice_id='$invoice_id' and i.stu_linking_id='$root_id'
                            and la.deleted=0 and la.actived=1 and il.deleted=0 and il.actived=1 
                            and l.deleted=0 and l.actived=1";
                            $result1 = $dbh->query($query1);
                            $result1->setFetchMode(PDO::FETCH_OBJ);
                            if ($result1) {
                                while ($row = $result1->fetch()) {
                                    $hour = round($row->hour, 2);
                                    $price = $row->original_fee;
                                    $amount = $row->amount;
                                    $discount = $row->discounted_fee;
                                    $total_price +=$price;
                                    $total_discount +=$discount;
                                    $total_amount +=$amount;
                                    ?>
                                    <tr>
                                        <!--<td><input type="checkbox" name="lesson_id[]" value="<? //= $row->lesson_id                               ?>"></td>-->
                                        <td>
                                            <input type="hidden" name="lesson_id[]" id="lesson_<?= $i ?>" value="<?= $row->lesson_id ?>" checked onclick="selected(this);">
                                            <?= $row->date . '(' . $row->weekday . ')' ?><input type="hidden" name="date[]" value="<?= $row->date ?>">
                                        </td>
                                        <td><?= $row->start_time ?><input type="hidden" name="start_time[]" value="<?= $row->start_time ?>"></td>
                                        <td><?= $row->end_time ?><input type="hidden" name="end_time[]" value="<?= $row->end_time ?>"></td>
                                        <td><?= $row->hour ?><input type="hidden" name="hours[]" value="<?= $row->hour ?>"></td>
                                        <td>
                                            <?php
                                            if ($row->event_programme_fee_type == 1) {
                                                echo 'Hourly' . '<input type="hidden" name="fee_type[]" value="1">';
                                            } else {
                                                if ($row->event_programme_fee_type == 2) {
                                                    echo 'Package' . '<input type="hidden" name="fee_type[]" value="2">';
                                                } else {
                                                    echo 'Free' . '<input type="hidden" name="fee_type[]" value="3">';
                                                }
                                            }
                                            ?>
                                        </td>
                                        <td><?= $row->original_fee ?><input type="hidden" name="price[]" id='price_<?= $i ?>' value="<?= $row->original_fee ?>"></td>
                                        <td>
                                            <?php
                                            if ($row->attendance == 1) {
                                                echo 'Present';
                                                echo '<input type="hidden" name="attendance[]" value="1">';
                                            } else {
                                                echo 'Absent';
                                                echo '<input type="hidden" name="attendance[]" value="0">';
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php
                                            if ($row->discount_type == 1) {
                                                ?>
                                                <select name="type[]" style="width:100%;" id="type_<?= $i ?>" onchange="change_discount(this);" disabled="true">
                                                    <option value="1" selected>Subsidy</option>
                                                    <option value="2">Package discount</option>
                                                    <!--<option value="3">Funding</option>-->
                                                </select>
                                            </td>

                                            <td><input type="number" style="width:60px;" name="type_rate[]" id="typerate_<?= $i ?>" value="<?= $row->subsidy_percent ?>" readonly='true' onblur="funding(this);"></td>
                                            <?php
                                        } else {
                                            if ($row->discount_type == 2) {
                                                ?>
                                            <select name="type[]" style="width:100%;" id="type_<?= $i ?>" onchange="change_discount(this);" disabled="true">
                                                <option value="1">Subsidy</option>
                                                <option value="2" selected>Package discount</option>
                                                <!--<option value="3">Funding</option>-->
                                            </select>
                                            </td>

                                            <td><input type="number" style="width:60px;" name="type_rate[]" id="typerate_<?= $i ?>" value="<?= $row->discounted_fee ?>" readonly='true' onblur="funding(this);"></td>
                                            <?php
                                        }
                                    }
                                    ?>
                                    <td><input type="number" name="discount[]" style="width:90%;" id="discount_<?= $i ?>" value="<?= $row->discounted_fee ?>" readonly='true'></td>
                                    <?php if ($row->is_charge == 1) { ?>
                                        <td><input type="checkbox" name="is_charge[]" id="charge_<?= $i ?>" onclick="not_charge(this);" value="1" disabled="true"></td>
                                        <?php
                                    } else {
                                        ?>
                                        <td><input type="checkbox" name="is_charge[]" id="charge_<?= $i ?>" onclick="not_charge(this);" value="1" disabled="true" checked></td>
                                        <?php
                                    }
                                    ?>
                                    <td><input type="text" name="amount[]" style="width:90%;" id='amount_<?= $i ?>' value="<?= $row->amount ?>" readonly="true"></td>
                                    </tr>
                                    <?php
                                    $i++;
                                }
                            } else {
                                echo '<script>alert("error1.)</script>';
                            }
                            ?>
                            <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>Total price:<?= $row1->total_original_fee ?><input type="hidden" name="total_price" value='<?= $row1->total_original_fee ?>'></td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>Total discount:<input type='text' style="width:90%;" name='total_discount' id='total_discount' value='<?= $row1->total_discount_fee ?>' readonly='true'></td>
                                <td>&nbsp;</td>
                                <td>
                                    Total amount:<input type='text' style="width:90%;" name='total_amount' id='total_amount' value='<?= $row1->total_amount ?>' readonly='true'>
                                    <input type="hidden" name="i" id="i" value="<?= $i ?>">
                                </td>
                            </tr>
                        </table>
                        <a href="invoice_edit.php?linking_id=<?= $linking_id ?>&invoice_id=<?= $invoice_id ?>&stu_root_id=<?= $root_id ?>&action=Edit" class="btn">Edit</a>
                        <input type="submit" name="Export" value="Export to Excel" class="btn">
                    </form>
                    <?php
                } else {
                    if (isset($_GET['school_id'])) {
                        $sch_id = $_GET['school_id'];
                        $invoice_id = $_GET['invoice_id'];

                        //in-school invoice
                        ?>
                        <form action="" method="POST" class="form-inline">
                            <table border="0" class="table table-striped table-bordered table-hover table-condensed" width="100%">
                                <?php
                                $query = "Select i.description,i.invoice_code,i.invoice_date,i.event_code,i.total_original_fee,i.school_id,
                                i.total_amount,sub.sub_name,prog.program_name,sch.sch_name from invoice as i,
                                subject as sub,program as prog,event as e,school as sch where i.event_code=e.event_code
                                 and e.program_id=prog.program_id and e.subject_id=sub.subject_id and i.school_id=sch.school_id
                                  and i.school_id='$sch_id' and i.deleted=0 and i.actived=1";

                                $result = $dbh->query($query); //get invoice data
                                $result->setFetchMode(PDO::FETCH_OBJ);
                                $row = $result->fetch();
                                if ($result) {
                                    $total_price = 0.0;
                                    $total_discount = 0.0;
                                    $total_amount = 0.0;
                                    $total_hr = 0.0;
                                    $i = 0;
                                    ?>
                                    <tr>
                                        <td colspan="6"><center><h3>INVOICE</h3></center></td>
                                    </tr>
                                    <tr>
                                        <td>Bill To:</td>
                                        <td colspan="2">
                                            <input type="text" name="bill_to" required="true" readonly="true" value="<?= $row->sch_name ?>" readonly="true">
                                            <input type="hidden" name="sch_id" id="sch_id" value="<?= $row->school_id ?>">
                                            <input type="hidden" name="root_id" id="root_id" value="<?= $row->root_id ?>">

                                        </td>
                                        <td>Invoice Date:</td>
                                        <td colspan="2">
                                            <input type="text" name="invoice_date" readonly="true" required='true' value="<?= $row->invoice_date ?>">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Program-Subject</td>
                                        <td colspan="2"><input type="text" name="prog_sub" value="<?= $row->program_name . '-' . $row->sub_name ?>" readonly="true"></td>
                                        <td>Invoice Code:</td>
                                        <td colspan="2"><input type="text" name="invoice_code" value="<?= $row->invoice_code ?>" readonly="true"></td>
                                    </tr>
                                    <tr>
                                        <td>Funding Type</td>
                                        <td colspan="2">
                                            <select name="funding_type" disabled="true">
                                                <option value="0">No Funding</option>
                                                <?php
                                                $query_funding = "Select funding_id,funding_type from funding where deleted=0 and actived=1";
                                                $result_funding = $dbh->query($query_funding);
                                                $result_funding->setFetchMode(PDO::FETCH_OBJ);
                                                while ($row_funding = $result_funding->fetch()) {
                                                    if ($row_funding->funding_id == $row->funding_type) {
                                                        ?>
                                                        <option value="<?= $row_funding->funding_id ?>" selected><?= $row_funding->funding_type ?></option>
                                                        <?php
                                                    } else {
                                                        ?>
                                                        <option value="<?= $row_funding->funding_id ?>"><?= $row_funding->funding_type ?></option>
                                                        <?php
                                                    }
                                                }
                                                ?>
                                            </select>
                                        </td>
                                        <td>Event Code:</td>
                                        <td colspan="2"><input type="text" name="event_code" value="<?= $row->event_code ?>" readonly="true"></td>
                                    </tr>
                                    <tr>
                                        <th>Date</th>
                                        <th>Time from</th>
                                        <th>Time to</th>
                                        <th>Hour(s)</th>
                                        <th>Not Charge?</th>
                                        <th>Amount($)</th>
                                    </tr>
                                    <?php
                                    $query_get_activity = "Select DATE_FORMAT(act.date, '%W') as weekday,il.is_charge,il.activity_id,il.amount,il.hour,il.remarks,act.date,act.start_time,act.end_time from invoice_line as il,
                                        activity as act,invoice as i where il.activity_id=act.activity_id and 
                                        i.invoice_id=il.invoice_id and il.invoice_id='$invoice_id' and i.school_id='$sch_id'
                                        and il.deleted=0 and il.actived=1 and act.deleted=0 and act.actived=1";
                                    $result_get_activity = $dbh->query($query_get_activity);
                                    $result_get_activity->setFetchMode(PDO::FETCH_OBJ);
                                    while ($row_activity = $result_get_activity->fetch()) {
                                        //$query_get_stu = "Select count(*) as no_of_stu from activity_stu_list where activity_id='$row_activity->activity_id'";
                                        //$result_get_stu = $dbh->query($query_get_stu);
                                        //$result_get_stu->setFetchMode(PDO::FETCH_OBJ);
                                        //$no_of_stu = $result_get_stu->fetch()->no_of_stu;
                                        //cal amount and hr
                                        $hour = round($row_activity->hour, 2);
                                        $price = $row_activity->amount;
                                        $amount = $price;
                                        $total_price += $price;
                                        $total_amount += $amount;
                                        $total_hr+=$hour;
                                        ?>
                                        <tr>
                                            <td><input type="hidden" name="activity_id[]" id="activity_<?= $i ?>" value="<?= $row_activity->lesson_id ?>" checked onclick="//selected(this);">
                                                <?= $row_activity->date ?><input type="hidden" name="date[]" value="<?= $row_activity->date ?>"></td>
                                            <td><?= $row_activity->start_time ?><input type="hidden" name="start_time[]" value="<?= $row_activity->start_time ?>"></td>
                                            <td><?= $row_activity->end_time ?><input type="hidden" name="end_time[]" value="<?= $row_activity->end_time ?>"></td>
                                            <td><?= $hour ?><input type="hidden" name="hours[]" value="<?= $hour ?>"></td>
                                            <?php if ($row_activity->is_charge == 1) { ?>
                                                <td><input type="checkbox" name="is_charge[]" id="charge_<?= $i ?>" onclick="not_charge(this);" value="1" disabled="true"></td>
                                                <?php
                                            } else {
                                                ?>
                                                <td><input type="checkbox" name="is_charge[]" id="charge_<?= $i ?>" onclick="not_charge(this);" value="1" checked disabled="true"></td>
                                                <?php
                                            }
                                            ?>
                                            <td><input type="text" name="amount[]" id='amount_<?= $i ?>' value="<?= $amount ?>" readonly="true"></td>
                                        </tr>
                                        <?php
                                        $i++;
                                    }//get activity

                                    $query1 = "Select il.is_charge,il.lesson_id,il.amount,il.hour,il.remarks,l.date,l.start_time,l.end_time from invoice_line as il,
                                        lesson as l,invoice as i where il.lesson_id=l.lesson_id and 
                                        i.invoice_id=il.invoice_id and il.invoice_id='$invoice_id' and i.school_id='$sch_id'
                                        and il.deleted=0 and il.actived=1 and l.deleted=0 and l.actived=1";
                                    $result1 = $dbh->query($query1);
                                    $result1->setFetchMode(PDO::FETCH_OBJ);
                                    /* $query4 = "Select Max(invoice_id) as i from invoice";
                                      $result4 = $dbh->query($query4);
                                      $result4->setFetchMode(PDO::FETCH_OBJ);
                                      $row4 = $result4->fetch(); */

                                    while ($row1 = $result1->fetch()) {
                                        $hour = round($row1->hour, 2);
                                        $price = $row1->amount;
                                        $amount = $price;
                                        $total_price += $price;
                                        $total_amount += $amount;
                                        $total_hr+=$hour;
                                        ?>
                                        <tr>
                                            <td><input type="hidden" name="lesson_id[]" id="lesson_<?= $i ?>" value="<?= $row1->lesson_id ?>" checked onclick="//selected(this);">
                                                <?= $row1->date ?><input type="hidden" name="date[]" value="<?= $row->date ?>"></td>
                                            <td><?= $row1->start_time ?><input type="hidden" name="start_time[]" value="<?= $row1->start_time ?>"></td>
                                            <td><?= $row1->end_time ?><input type="hidden" name="end_time[]" value="<?= $row1->end_time ?>"></td>
                                            <td><?= (strtotime($row1->end_time) - strtotime($row1->start_time)) / 3600 ?><input type="hidden" name="hours[]" value="<?= (strtotime($row1->end_time) - strtotime($row1->start_time)) / 3600 ?>"></td>
                                            <?php if ($row1->is_charge == 1) { ?>
                                                <td><input type="checkbox" name="is_charge[]" id="charge_<?= $i ?>" onclick="not_charge(this);" value="1" disabled="true"></td>
                                                <?php
                                            } else {
                                                ?>
                                                <td><input type="checkbox" name="is_charge[]" id="charge_<?= $i ?>" onclick="not_charge(this);" value="1" checked disabled="true"></td>
                                                <?php
                                            }
                                            ?>
                                            <td><input type="text" name="amount[]" id='amount_<?= $i ?>' value="<?= $amount ?>" readonly="true"></td>
                                        </tr>
                                        <?php
                                        $i++;
                                    }
                                    ?>
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>
                                            Total price:<?= $total_price ?><input type="hidden" name="total_price" value='<?= $total_price ?>'>
                                            <input type='hidden' name='total_discount' id='total_discount' value='<?= $total_discount ?>'>
                                        </td>
                                        <td>Total hours:<input type="text" name="desc" readonly="true" value="<?= $total_hr ?> hour(s)"></td>
                                        <td>&nbsp;</td>
                                        <td>
                                            Total amount:<br><input type='text' name='total_amount' id='total_amount' value='<?= $total_amount ?>' readonly='true'>
                                            <input type="hidden" name="i" id="i" value="<?= $i ?>">
                                        </td>
                                    </tr>
                                </table>
                                <a href="invoice_edit.php?school_id=<?= $row->school_id ?>&invoice_id=<?= $invoice_id ?>&action=Edit" class="btn">Edit</a>
                                <input type="submit" name="Export1" value="Export to Excel" class="btn">
                            </form>
                            <?php
                        }
                    }
                }
            } else {
                if (isset($_GET['stu_root_id'])) {
                    $root_id = $_GET['stu_root_id']; //stu_root_id
                    $invoice_id = $_GET['invoice_id'];
                    $linking_id = $_GET['linking_id'];
                    ?>
                    <form action="" method="POST" class="form-inline">
                        <input type="hidden" name="linking_id" id="linking_id" value="<?= $linking_id ?>">
                        <table border="0" class="table table-striped table-bordered table-hover table-condensed" width="100%">
                            <?php
                            $total_price = 0;
                            $total_discount = 0;
                            $total_amount = 0;
                            $i=0;
                            $query = "Select i.invoice_code,i.invoice_date,i.event_code,i.total_original_fee,i.total_discount_fee,
                                i.total_amount,sub.sub_name,prog.program_name,e.school_id,stu.linking_id,stu.last_name,stu.first_name from invoice as i,
                                student as stu,subject as sub,program as prog,event as e where i.event_code=e.event_code
                                 and e.program_id=prog.program_id and e.subject_id=sub.subject_id and i.stu_linking_id=stu.root_id
                                  and i.stu_linking_id='$root_id' group by i.invoice_code";
                            $result1 = $dbh->query($query); //get invoice data
                            $result1->setFetchMode(PDO::FETCH_OBJ);
                            $row1 = $result1->fetch();
                            if ($row1->school_id == 0) {
                                ?>
                                <tr>
                                    <td colspan="14"><center><h3>INVOICE</h3></center></td>
                                </tr>
                                <tr>
                                    <td colspan="3">Bill To:</td>
                                    <td colspan="3">
                                        <input type="text" name="bill_to" required="true" value="<?= $row1->last_name . ' ' . $row1->first_name ?>" readonly="true">
                                        <input type="hidden" name="root_id" id="root_id" value="<?= $root_id ?>">
                                        <input type="hidden" name="linking_id" id="linking_id" value="<?= $linking_id ?>">
                                        <input type="hidden" name="invoice_id" id="invoice_id" value="<?= $invoice_id ?>">
                                        <input type="hidden" name="invoice_code" value="<?= $row1->invoice_code ?>">
                                    </td>
                                    <td colspan="2">Invoice Date:</td>
                                    <td colspan="5">
                                        <div class="input-append date-picker">
                                            <input type="text" name="invoice_date" class="dateISO" required='true' value="<?= $row1->invoice_date ?>">
                                            <span class="add-on">
                                                <i class="icon-calendar" data-date-icon="icon-calendar" data-time-icon="icon-time"></i>
                                            </span>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="3">Program-Subject</td>
                                    <td colspan="3"><input type="text" name="prog_sub" value="<?= $row1->program_name . '-' . $row1->sub_name ?>" readonly="true"></td>
                                    <td colspan="2">Invoice Code:</td>
                                    <td colspan="5"><input type="text" name="invoice_code" value="<?= $row1->invoice_code ?>" readonly="true"></td>
                                </tr>
                                <tr>
                                    <td colspan="3">Funding Type</td>
                                    <td colspan="3">
                                        <select name="funding_type">
                                            <option value="0">No Funding</option>
                                            <?php
                                            $query_funding = "Select funding_id,funding_type from funding where deleted=0 and actived=1";
                                            $result_funding = $dbh->query($query_funding);
                                            $result_funding->setFetchMode(PDO::FETCH_OBJ);
                                            while ($row_funding = $result_funding->fetch()) {
                                                if ($row_funding->funding_id == $row1->funding_type) {
                                                    ?>
                                                    <option value="<?= $row_funding->funding_id ?>" selected><?= $row_funding->funding_type ?></option>
                                                    <?php
                                                } else {
                                                    ?>
                                                    <option value="<?= $row_funding->funding_id ?>"><?= $row_funding->funding_type ?></option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </select>
                                    </td>
                                    <td colspan="2">Event Code:</td>
                                    <td colspan="5"><input type="text" name="event_code" value="<?= $row1->event_code ?>" readonly="true"></td>
                                </tr>
                                <tr>
                                    <th>Date</th>
                                    <th>Time from</th>
                                    <th>Time to</th>
                                    <th>Hour(s)</th>
                                    <th>Fee type</th>
                                    <th>Price($)</th>
                                    <th>Attendance</th>
                                    <th>Subsidy(%)/Package discount($)</th>
                                    <th>&nbsp;</th>
                                    <th>Discount($)</th>
                                    <th>Not Charge?</th>
                                    <th>Amount($)</th>
                                </tr>
                                <?php
                            }

                            $query_get_activity = "Select DATE_FORMAT(act.date, '%W') as weekday,act.date,il.activity_id,il.event_programme_fee_type,il.discount_type,il.original_fee,il.discounted_fee,il.amount,il.hour,
                            il.subsidy_percent,il.is_charge,act.start_time,act.end_time from activity as act,activity_stu_list as act_stu,invoice_line as il,event as e ,
                            invoice as i where act.event_id=e.event_id and i.event_code=e.event_code and
                            i.invoice_id=il.invoice_id and il.invoice_id='$invoice_id' and i.stu_linking_id='$root_id' and il.activity_id<>''
                             and il.deleted=0 and il.actived=1 and act.deleted=0 and act.actived=1";
                            $result_get_activity = $dbh->query($query_get_activity);
                            $result_get_activity->setFetchMode(PDO::FETCH_OBJ);
                            while ($row_activity = $result_get_activity->fetch()) {
                                $hour = round($row_activity->hour, 2);
                                $price = $row_activity->original_fee;
                                $amount = $row_activity->amount;
                                $discount = $row_activity->discounted_fee;
                                $total_price +=$price;
                                $total_discount +=$discount;
                                $total_amount +=$amount;
                                ?>
                                <tr>
                                    <td><input type="hidden" name="activity_id[]" id="activity_<?= $i ?>" value="<?= $row_activity->activity_id ?>" checked onclick="//selected(this);">
                                        <?= $row_activity->date . '(' . $row_activity->weekday . ')' ?><input type="hidden" name="date[]" value="<?= $row_activity->date ?>"></td>
                                    <td><?= $row_activity->start_time ?><input type="hidden" name="start_time[]" value="<?= $row_activity->start_time ?>"></td>
                                    <td><?= $row_activity->end_time ?><input type="hidden" name="end_time[]" value="<?= $row_activity->end_time ?>"></td>
                                    <td><?= $hour ?><input type="hidden" name="hours[]" value="<?= $hour ?>"></td>
                                    <td>Assessment/Test</td>
                                    <td><?= $price ?><input type="hidden" name="price[]" id='price_<?= $i ?>' value="<?= $price ?>"></td>
                                    <td>/</td><!--attendance-->
                                    <td>
                                        <?php
                                        if ($row_activity->discount_type == 1) {
                                            ?>
                                            <select name="type[]" style="width:100%;" id="type_<?= $i ?>" onchange="change_discount(this);">
                                                <option value="1" selected>Subsidy</option>
                                                <option value="2">Package discount</option>
                                                <!--<option value="3">Funding</option>-->
                                            </select>
                                        </td>

                                        <td><input type="number" style="width:60px;" name="type_rate[]" id="typerate_<?= $i ?>" value="<?= $row_activity->subsidy_percent ?>" readonly='true' onblur="funding(this);"></td>
                                        <?php
                                    } else {
                                        if ($row_activity->discount_type == 2) {
                                            ?>
                                        <select name="type[]" style="width:100%;" id="type_<?= $i ?>" onchange="change_discount(this);">
                                            <option value="1">Subsidy</option>
                                            <option value="2" selected>Package discount</option>
                                            <!--<option value="3">Funding</option>-->
                                        </select>
                                        </td>

                                        <td><input type="number" style="width:60px;" name="type_rate[]" id="typerate_<?= $i ?>" value="<?= $row_activity->discounted_fee ?>" readonly='true' onblur="funding(this);"></td>
                                        <?php
                                    }
                                }
                                ?>
                                <td><input type="number" style="width:90%;" name="discount[]" id="discount_<?= $i ?>" value="<?= $discount ?>" readonly='true'></td>

                                <?php if ($row_activity->is_charge == 1) { ?>
                                    <td><input type="checkbox" name="is_charge[]" id="charge_<?= $i ?>" onclick="not_charge(this);" value="1"></td>
                                    <?php
                                } else {
                                    ?>
                                    <td><input type="checkbox" name="is_charge[]" id="charge_<?= $i ?>" onclick="not_charge(this);" value="1" checked></td>
                                    <?php
                                }
                                ?>

                                <td><input type="text" style="width:90%;" name="amount[]" id='amount_<?= $i ?>' value="<?= $amount ?>" readonly="true"></td>
                                </tr>
                                <?php
                                $i++;
                            }

                            $query1 = "Select DATE_FORMAT(l.date, '%W') as weekday,il.lesson_id,il.event_programme_fee_type,il.discount_type,il.original_fee,il.discounted_fee,il.amount,il.hour,
                            il.subsidy_percent,il.is_charge,il.remarks,l.date,l.start_time,l.end_time,la.attendance from invoice_line as il,
                            lesson as l,lesson_attendance as la,invoice as i where il.lesson_id=l.lesson_id and la.lesson_id=il.lesson_id and 
                            la.stu_linking_id=i.stu_linking_id and i.invoice_id=il.invoice_id and il.invoice_id='$invoice_id' and i.stu_linking_id='$root_id'
                            and la.deleted=0 and la.actived=1 and il.deleted=0 and il.actived=1 
                            and l.deleted=0 and l.actived=1";
                            $result1 = $dbh->query($query1);
                            $result1->setFetchMode(PDO::FETCH_OBJ);
                            if ($result1) {

                                while ($row = $result1->fetch()) {
                                    /* $query1 = "Select ss.stu_subsidy_id,s.percent as sum_p from student_subsidy as ss, subsidy as s where ss.subsidy_id = s.subsidy_id and ss.deleted=0 and s.deleted=0
                                      and s.actived=1 and ss.actived=1 and ss.stu_subsidy_id='$stu_id'";
                                      $result1 = $dbh->query($query1); //get percent
                                      if ($result1->rowcount() == 0) {
                                      $percent = 0;
                                      }
                                      else {
                                      $result1->setFetchMode(PDO::FETCH_OBJ);
                                      $row1 = $result1->fetch();
                                      $percent = $row1->sum_p;
                                      }
                                      } */
                                    ?>
                                    <tr>
                                        <!--<td><input type="checkbox" name="lesson_id[]" value="<? //= $row->lesson_id                              ?>"></td>-->
                                        <td>
                                            <input type="hidden" name="lesson_id[]" id="lesson_<?= $i ?>" value="<?= $row->lesson_id ?>" checked onclick="selected(this);">
                                            <?= $row->date . '(' . $row->weekday . ')' ?><input type="hidden" name="date[]" value="<?= $row->date ?>">
                                        </td>
                                        <td><?= $row->start_time ?><input type="hidden" name="start_time[]" value="<?= $row->start_time ?>"></td>
                                        <td><?= $row->end_time ?><input type="hidden" name="end_time[]" value="<?= $row->end_time ?>"></td>
                                        <td><?= $row->hour ?><input type="hidden" name="hours[]" value="<?= $row->hour ?>"></td>
                                        <td>
                                            <?php
                                            if ($row->event_programme_fee_type == 1) {
                                                echo 'Hourly' . '<input type="hidden" name="fee_type[]" value="1">';
                                            } else {
                                                if ($row->event_programme_fee_type == 2) {
                                                    echo 'Package' . '<input type="hidden" name="fee_type[]" value="2">';
                                                } else {
                                                    echo 'Free' . '<input type="hidden" name="fee_type[]" value="3">';
                                                }
                                            }
                                            ?>
                                        </td>
                                        <td><?= $row->original_fee ?><input type="hidden" name="price[]" id='price_<?= $i ?>' value="<?= $row->original_fee ?>"></td>
                                        <td>
                                            <?php
                                            if ($row->attendance == 1) {
                                                echo 'Present';
                                                echo '<input type="hidden" name="attendance[]" value="1">';
                                            } else {
                                                echo 'Absent';
                                                echo '<input type="hidden" name="attendance[]" value="0">';
                                            }
                                            ?>
                                        </td>

                                        <td>
                                            <?php
                                            if ($row->discount_type == 1) {
                                                ?>
                                                <select name="type[]" style="width:100%" id="type_<?= $i ?>" onchange="change_discount(this);">
                                                    <option value="1" selected>Subsidy</option>
                                                    <option value="2">Package discount</option>
                                                </select>
                                            </td>

                                            <td><input type="number" style="width:80%" name="type_rate[]" id="typerate_<?= $i ?>" value="<?= $row->subsidy_percent ?>" readonly='true' onblur="funding(this);"></td>
                                            <?php
                                        } else {
                                            if ($row->discount_type == 2) {
                                                ?>
                                            <select name="type[]" style="width:100%" id="type_<?= $i ?>" onchange="change_discount(this);">
                                                <option value="1">Subsidy</option>
                                                <option value="2" selected>Package discount</option>
                                            </select>
                                            </td>

                                            <td><input type="number"  style="width:80%" name="type_rate[]" id="typerate_<?= $i ?>" value="<?= $row->discounted_fee ?>" readonly='true' onblur="funding(this);"></td>
                                            <?php
                                        } else {
                                            ?>
                                            <select name="type[]" style="width:100%" id="type_<?= $i ?>" onchange="change_discount(this);">
                                                <option value="1">Subsidy</option>
                                                <option value="2">Package discount</option>
                                            </select>
                                            </td>

                                            <td><input type="number" style="width:80%" name="type_rate[]" id="typerate_<?= $i ?>" value="<?= $row->discounted_fee ?>" readonly='true' onblur="funding(this);"></td>
                                            <?php
                                        }
                                    }
                                    ?>
                                    <td><input type="number" style="width:90%" name="discount[]" id="discount_<?= $i ?>" value="<?= $row->discounted_fee ?>" readonly='true'></td>
                                    <?php if ($row->is_charge == 1) { ?>
                                        <td><input type="checkbox" name="is_charge[]" id="charge_<?= $i ?>" onclick="not_charge(this);" value="1"></td>
                                        <?php
                                    } else {
                                        ?>
                                        <td><input type="checkbox" name="is_charge[]" id="charge_<?= $i ?>" onclick="not_charge(this);" value="1" checked></td>
                                        <?php
                                    }
                                    ?>
                                    <td><input type="text" style="width:90%" name="amount[]" id='amount_<?= $i ?>' value="<?= $row->amount ?>" readonly="true"></td>
                                    </tr>
                                    <?php
                                    $i++;
                                }
                            } else {
                                echo '<script>alert("Error 10")</script>';
                            }
                            ?>
                            <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>Total price:<?= $row1->total_original_fee ?><input type="hidden" name="total_price" value='<?= $row1->total_original_fee ?>'></td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>Total discount:<input type='text' style="width:90%" name='total_discount' id='total_discount' value='<?= $row1->total_discount_fee ?>' readonly='true'></td>
                                <td>&nbsp;</td>
                                <td>
                                    Total amount:<input type='text' style="width:90%" name='total_amount' id='total_amount' value='<?= $row1->total_amount ?>' readonly='true'>
                                    <input type="hidden" name="i" id="i" value="<?= $i ?>">
                                </td>
                            </tr>
                        </table>
                        <input type="submit" name="edit" value="Save" class="btn">
                    </form>
                    <?php
                } else {
                    if (isset($_GET['school_id'])) {
                        $sch_id = $_GET['school_id'];
                        $invoice_id = $_GET['invoice_id'];

                        //in-school invoice
                        ?>
                        <form action="" method="POST" class="form-inline">
                            <table border="0" class="table table-striped table-bordered table-hover table-condensed" width="100%">
                                <?php
                                $query = "Select i.invoice_code,i.invoice_date,i.event_code,i.total_original_fee,i.school_id,
                                i.total_amount,sub.sub_name,prog.program_name,sch.sch_name from invoice as i,
                                subject as sub,program as prog,event as e,school as sch where i.event_code=e.event_code
                                 and e.program_id=prog.program_id and e.subject_id=sub.subject_id and i.school_id=sch.school_id
                                  and i.school_id='$sch_id' and i.deleted=0 and i.actived=1";

                                $result = $dbh->query($query); //get invoice data
                                $result->setFetchMode(PDO::FETCH_OBJ);
                                $row = $result->fetch();
                                if ($result) {
                                    $total_price = 0.0;
                                    $total_discount = 0.0;
                                    $total_amount = 0.0;
                                    $total_hr = 0.0;
                                    $i = 0;
                                    ?>
                                    <tr>
                                        <td colspan="6"><center><h3>INVOICE</h3></center></td>
                                    </tr>
                                    <tr>
                                        <td>Bill To:</td>
                                        <td colspan="2">
                                            <input type="text" name="bill_to" required="true" readonly="true" value="<?= $row->sch_name ?>" readonly="true">
                                            <input type="hidden" name="sch_id" id="sch_id" value="<?= $row->school_id ?>">
                                            <input type="hidden" name="invoice_code" value="<?= $row->invoice_code ?>">
                                        </td>
                                        <td>Invoice Date:</td>
                                        <td colspan="2">
                                            <div class="input-append date-picker">
                                                <input type="text" name="invoice_date" class="dateISO" required='true' value="<?= $row->invoice_date ?>">
                                                <span class="add-on">
                                                    <i class="icon-calendar" data-date-icon="icon-calendar" data-time-icon="icon-time"></i>
                                                </span>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Program-Subject</td>
                                        <td colspan="2"><input type="text" name="prog_sub" value="<?= $row->program_name . '-' . $row->sub_name ?>" readonly="true"></td>
                                        <td>Invoice Code:</td>
                                        <td colspan="2"><input type="text" name="invoice_code" value="<?= $row->invoice_code ?>" readonly="true"></td>
                                    </tr>
                                    <tr>
                                        <td>Funding Type</td>
                                        <td colspan="2">
                                            <select name="funding_type">
                                                <option value="0">No Funding</option>
                                                <?php
                                                $query_funding = "Select funding_id,funding_type from funding where deleted=0 and actived=1";
                                                $result_funding = $dbh->query($query_funding);
                                                $result_funding->setFetchMode(PDO::FETCH_OBJ);
                                                while ($row_funding = $result_funding->fetch()) {
                                                    if ($row_funding->funding_id == $row->funding_type) {
                                                        ?>
                                                        <option value="<?= $row_funding->funding_id ?>" selected><?= $row_funding->funding_type ?></option>
                                                        <?php
                                                    } else {
                                                        ?>
                                                        <option value="<?= $row_funding->funding_id ?>"><?= $row_funding->funding_type ?></option>
                                                        <?php
                                                    }
                                                }
                                                ?>
                                            </select>
                                        </td>
                                        <td>Event Code:</td>
                                        <td colspan="2"><input type="text" name="event_code" value="<?= $row->event_code ?>" readonly="true"></td>
                                    </tr>
                                    <tr>
                                        <th>Date</th>
                                        <th>Time from</th>
                                        <th>Time to</th>
                                        <th>Hour(s)</th>
                                        <th>Not Charge?</th>
                                        <th>Amount($)</th>
                                    </tr>
                                    <?php
                                    
                                    $query_get_activity = "Select DATE_FORMAT(act.date, '%W') as weekday,il.is_charge,il.activity_id,il.amount,il.hour,il.remarks,act.date,act.start_time,act.end_time from invoice_line as il,
                                        activity as act,invoice as i where il.activity_id=act.activity_id and 
                                        i.invoice_id=il.invoice_id and il.invoice_id='$invoice_id' and i.school_id='$sch_id'
                                        and il.deleted=0 and il.actived=1 and act.deleted=0 and act.actived=1";
                                    $result_get_activity = $dbh->query($query_get_activity);
                                    $result_get_activity->setFetchMode(PDO::FETCH_OBJ);
                                    while ($row_activity = $result_get_activity->fetch()) {
                                        //$query_get_stu = "Select count(*) as no_of_stu from activity_stu_list where activity_id='$row_activity->activity_id'";
                                        //$result_get_stu = $dbh->query($query_get_stu);
                                        //$result_get_stu->setFetchMode(PDO::FETCH_OBJ);
                                        //$no_of_stu = $result_get_stu->fetch()->no_of_stu;
                                        //cal amount and hr
                                        $hour = round($row_activity->hour, 2);
                                        $price = $row_activity->amount;
                                        $amount = $price;
                                        $total_price += $price;
                                        $total_amount += $amount;
                                        $total_hr+=$hour;
                                        ?>
                                        <tr>
                                            <td><input type="hidden" name="activity_id[]" id="activity_<?= $i ?>" value="<?= $row_activity->activity_id ?>" checked onclick="//selected(this);">
                                                <?= $row_activity->date ?><input type="hidden" name="date[]" value="<?= $row_activity->date ?>"></td>
                                            <td><?= $row_activity->start_time ?><input type="hidden" name="start_time[]" value="<?= $row_activity->start_time ?>"></td>
                                            <td><?= $row_activity->end_time ?><input type="hidden" name="end_time[]" value="<?= $row_activity->end_time ?>"></td>
                                            <td><?= $hour ?><input type="hidden" name="hours[]" value="<?= $hour ?>"></td>
                                            <?php if ($row_activity->is_charge == 1) { ?>
                                                <td><input type="checkbox" name="is_charge[]" id="charge_<?= $i ?>" onclick="in_school_not_charge(this);" value="1"></td>
                                                <?php
                                            } else {
                                                ?>
                                                <td><input type="checkbox" name="is_charge[]" id="charge_<?= $i ?>" onclick="in_school_not_charge(this);" value="1" checked></td>
                                                <?php
                                            }
                                            ?>
                                            <td><input type="text" name="amount[]" id='amount_<?= $i ?>' value="<?= $amount ?>" readonly="true"></td>
                                        </tr>
                                        <?php
                                        $i++;
                                    }//get activity
                                    
                                    $query1 = "Select il.is_charge,il.lesson_id,il.amount,il.hour,il.remarks,l.date,l.start_time,l.end_time from invoice_line as il,
                                        lesson as l,invoice as i where il.lesson_id=l.lesson_id and 
                                        i.invoice_id=il.invoice_id and il.invoice_id='$invoice_id' and i.school_id='$sch_id'
                                        and il.deleted=0 and il.actived=1 and l.deleted=0 and l.actived=1";
                                    $result1 = $dbh->query($query1);
                                    $result1->setFetchMode(PDO::FETCH_OBJ);
                                    /* $query4 = "Select Max(invoice_id) as i from invoice";
                                      $result4 = $dbh->query($query4);
                                      $result4->setFetchMode(PDO::FETCH_OBJ);
                                      $row4 = $result4->fetch(); */

                                    while ($row1 = $result1->fetch()) {
                                        $hour = (round((strtotime($row1->end_time) - strtotime($row1->start_time)) / 3600, 2));
                                        $price = $row1->amount;
                                        $amount = $price;
                                        $total_price += $price;
                                        $total_amount += $amount;
                                        $total_hr+=$hour;
                                        ?>
                                        <tr>
                                            <td><input type="hidden" name="lesson_id[]" id="lesson_<?= $i ?>" value="<?= $row1->lesson_id ?>" checked onclick="//selected(this);">
                                                <?= $row1->date ?><input type="hidden" name="date[]" value="<?= $row->date ?>"></td>
                                            <td><?= $row1->start_time ?><input type="hidden" name="start_time[]" value="<?= $row1->start_time ?>"></td>
                                            <td><?= $row1->end_time ?><input type="hidden" name="end_time[]" value="<?= $row1->end_time ?>"></td>
                                            <td><?= (strtotime($row1->end_time) - strtotime($row1->start_time)) / 3600 ?><input type="hidden" name="hours[]" value="<?= (strtotime($row1->end_time) - strtotime($row1->start_time)) / 3600 ?>"></td>
                                            <?php if ($row1->is_charge == 1) { ?>
                                                <td><input type="checkbox" name="is_charge[]" id="charge_<?= $i ?>" onclick="not_charge(this);" value="1"></td>
                                                <?php
                                            } else {
                                                ?>
                                                <td><input type="checkbox" name="is_charge[]" id="charge_<?= $i ?>" onclick="not_charge(this);" value="1" checked></td>
                                                <?php
                                            }
                                            ?>
                                            <td>
                                                <input type="text" name="amount[]" id='amount_<?= $i ?>' value="<?= $amount ?>" readonly="true">
                                                <input type="hidden" name="temp_amount[]" id="temp_<?= $i ?>"  value="<?= $amount ?>">
                                            </td>
                                        </tr>
                                        <?php
                                        $i++;
                                    }
                                    ?>
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>
                                            Total price:<?= $total_price ?><input type="hidden" name="total_price" value='<?= $total_price ?>'>
                                            <input type='hidden' name='total_discount' id='total_discount' value='<?= $total_discount ?>'>
                                        </td>
                                        <td>Total hours:<input type="text" name="desc" readonly="true" value="<?= $total_hr ?> hour(s)"></td>
                                        <td>&nbsp;</td>
                                        <td>
                                            Total amount:<br><input type='text' name='total_amount' id='total_amount' value='<?= $total_amount ?>' readonly='true'>
                                            <input type="hidden" name="i" id="i" value="<?= $i ?>">
                                            <input type="hidden" name="invoice_id" value="<?= $invoice_id ?>">
                                        </td>
                                    </tr>
                                </table>
                                <input type="submit" name="edit1" value="Save" class="btn">
                            </form>
                            <?php
                        }
                    }
                }
            }
            ?>
        </div>
    </body>
</html>

Youez - 2016 - github.com/yon3zu
LinuXploit