| 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/old20140414/Receipt/ |
Upload File : |
<!DOCTYPE html>
<html>
<head>
<?php require_once '../include/head.php'; ?>
<?php require_once '../include/checkuser.php'; ?>
<?php require_once '../include/Nav_bar.php'; ?>
<?php include_once '../include/DBConnect.php'; ?>
<script>
var total = 0;
$(function() {
$('.date-picker').datetimepicker({pickTime: false});
$('.searchstun').select2();
$('.stun').select2();
$('.searchsch').select2();
$('.sch').select2();
$('#payway').change(function() {
var type = $('#payway').val();
$.get('receipt_search_ajax.php?paytype=' + type, ff);
});
$('#searchtype').change(function() {
var searchtype = $('#searchtype').val();
$.get('receipt_search_type_ajax.php?searchtype=' + searchtype, stff);
});
function stff(res) {
$('#searchtype_div').html(res);
}
;
function ff(res) {
$('#paytype_tr').html(res);
}
;
});
$(document).ready(function() {
$(function() {
$('#form').on('submit', function(e) {
var array = new Array();
alert((document.getElementsByName("selected_checked[]")).length);
for (var i = 0; i < (document.getElementsByName("selected_checked[]")).length; i++) {
if (document.getElementsByName("selected_checked[]")[i].checked == true) {
array.push((document.getElementsByName("selected_checked[]")[i].value));
total += parseInt((document.getElementsByName("invoice_pay[]")[i].value));
}
}
if (total != $('#total_fee').val()) {
alert('Not match the total amount');
total = 0;
e.preventDefault();
}
var array2 = new Array();
for (var i = 0; i < (document.getElementsByName("selected_checked[]")).length; i++) {
if (document.getElementsByName("selected_checked[]")[i].checked == true) {
array2.push((document.getElementsByName("selected_checked[]")[i].value));
if ((parseInt((document.getElementsByName("invoice_payed[]")[i].value)) + parseInt((document.getElementsByName("invoice_pay[]")[i].value))) > parseInt((document.getElementsByName("invoice_total_amount[]")[i].value))) {
alert('invoice pay larger then amount');
e.preventDefault();
}
;
}
}
});
});
});
</script>
<style>
.div-background {
border: 1px solid #E6E6E6;
border-radius: 6px 6px 6px 6px;
background-color: #EEEFDE;
padding-top: 10px;
padding-bottom: 10px;
}
</style>
</head>
<?php
$invoice_id;
$startdate = date('Y-m-d');
$enddate = date('Y-m-d');
$today = date('Y-m-d');
$name;
if (isset($_POST['save'])) {
$root_id;
$totalmoney = 0;
$countinvoice = 0;
$name = $_POST['from_name'];
$money = $_POST['total_fee'];
$payof = '';
foreach ($_POST['selected_checked'] as $selected_check) {
$procode;
$subcode;
$proid;
$subid;
$event_code = $_POST['selected_event'][$selected_check];
$searchevent = "select program_id , subject_id from event where event_code = '$event_code' and deleted = 0";
$result = $dbh->query($searchevent);
$result->setFetchMode(PDO::FETCH_OBJ);
while ($row = $result->fetch()) {
$proid = $row->program_id;
$subid = $row->subject_id;
}
$searchpro = "select program_name from program where program_id = '$proid' and deleted = 0";
$result = $dbh->query($searchpro);
$result->setFetchMode(PDO::FETCH_OBJ);
while ($row = $result->fetch()) {
$procode = $row->program_name;
}
$searchsub = "select sub_name from subject where subject_id = '$subid' and deleted = 0";
$result = $dbh->query($searchsub);
$result->setFetchMode(PDO::FETCH_OBJ);
while ($row = $result->fetch()) {
$subcode = $row->sub_name;
}
$payof .= $procode . ' ' . $subcode . ' ' . $_POST['payof'][$selected_check] . ' ' . $_POST['selected_invoicedate'] . ' ';
};
$payway = $_POST['payway'];
if ($payway == 1) {
$bank_name = $_POST['bankname'];
$cheque_no = $_POST['cheque_no'];
} else {
$bank_name = '0';
$cheque_no = '0';
}
$campus = $_POST['campus'];
$type = $_POST['type'];
$paydate = $_POST['paydate'];
$dontinsert = false;
$loadname;
if ($campus != 1 && $campus != 2) {
$dontinsert = true;
echo "<script>alert('plz select a campus!!!')</script>";
}
$receiptNo = '';
if ($campus == 1) {
$receiptNo .= 'ST';
} else if ($campus == 2) {
$receiptNo .= 'KL';
};
$curr_yr = date("Y");
$curr_mon = date("m");
if ($curr_mon < 9)
$curr_yr--;
$receiptNo .= substr($curr_yr, 2);
$countnum;
$searchnum = "select count(receipt_id) as countnum from receipt";
$result = $dbh->query($searchnum);
$result->setFetchMode(PDO::FETCH_OBJ);
while ($row = $result->fetch()) {
$countnum = $row->countnum;
}
if ($countnum < 10) {
$receiptNo .= '000' . $countnum;
} else if ($countnum < 100) {
$receiptNo .= '00' . $countnum;
} else if ($countnum < 1000) {
$receiptNo .= '0' . $countnum;
} else if ($countnum < 10000) {
$receiptNo .= $countnum;
} else {
echo "<script>alert('this campus's receipt num is full in this year')</script>";
}
if ($dontinsert == false) {
$sth = $dbh->prepare("INSERT INTO `receipt`(`receipt_code`, `createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `receipt_date`, `receipt_from`, `payment_of`, `total_amount`, `is_cash`, `bank_name`, `cheque_code`, `is_normal`, `campus_id`) VALUES (?,1,now(),1,now(),1,0,?,?,?,?,?,?,?,?,?)");
$sth->bindParam(1, $receiptNo);
$sth->bindParam(2, $paydate);
$sth->bindParam(3, $name);
$sth->bindParam(4, $payof);
$sth->bindParam(5, $money);
$sth->bindParam(6, $payway);
$sth->bindParam(7, $bank_name);
$sth->bindParam(8, $cheque_no);
$sth->bindParam(9, $type);
$sth->bindParam(10, $campus);
$sth->execute();
$result = $dbh->query("select max(receipt_id) as root_id from receipt where deleted = 0");
$result->setFetchMode(PDO::FETCH_OBJ);
while ($row = $result->fetch()) {
$root_id = $row->root_id;
}
$countinvoice = 0;
foreach ($_POST['selected_checked'] as $selectedcheck) {
$selectedinvoice = $_POST['selected_invoice'][$selectedcheck];
$sth = $dbh->prepare("INSERT INTO `invoice_receipt`(`invoice_id`, `createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `receipt_id`, `amount_paid`) VALUES (?,1,now(),1,now(),1,0,?,?)");
$sth->bindParam(1, $selectedinvoice);
$sth->bindParam(2, $root_id);
$sth->bindParam(3, $_POST['invoice_pay'][$selectedcheck]);
$sth->execute();
};
echo "<script>alert('Insert data successful.')</script>";
echo("<script>location.href ='receipt_index.php';</script>");
}
}
?>
<body>
<!-- line between nav bar and content -->
<div class="text-right">
<ul class="breadcrumb">
<li class="active">Receipt</li>
</ul>
</div>
<div class="container-fluid pathways-container">
<div>
<table border="0" width="100%">
<tr>
<td><h2>Add Receipt</h2></td>
</tr>
</table>
</div>
<div class="pathways-search">
<form id="search_form" class="form-inline" action="" method="POST">
<table>
<tr>
<td>
<div class="pathways-inline-block">
<select name="searchtype" id="searchtype">
<option></option>
<option <?php
if (isset($_POST['go'])) {
if ($_POST['searchtype'] == 1) {
?> selected="" <?php
}
}
?> value="1">in-house</option>
<option <?php
if (isset($_POST['go'])) {
if ($_POST['searchtype'] == 2) {
?> selected="" <?php
}
}
?> value="2">in-school</option>
</select>
</div>
</td>
<td>
<div id="searchtype_div">
<?php
if (isset($_POST['go'])) {
if (isset($_POST['searchstun'])) {
?> <div class="pathways-inline-block">
<label>Student</label>
<select name="searchstun" id="stun" class="stun" style="width:230px">
<option value="ALL"></option>
<?php $sth = $dbh->query("SELECT `root_id` root_id,linking_id,`New_stu_ID` id,CONCAT(last_name, ' ', first_name) studentname,`ch_name`FROM `student` WHERE `actived`=1 and`deleted`=0 group by `New_stu_ID`,`Sem_yr`"); ?>
<?php while ($ResultSet = $sth->fetch(PDO::FETCH_ASSOC)) { ?>
<option <?php
if (isset($_POST['go'])) {
if ($_POST['searchstun'] == $ResultSet['root_id']) {
?> selected <?php
}
}
?>value="<?= $ResultSet['root_id']; ?>"><?= $ResultSet['studentname'] ?> | <?= $ResultSet['id'] ?></option>
<?php } ?>
</select>
</div><?php
}
if (isset($_POST['searchsch'])) {
?>
<div class = "pathways-inline-block">
<label>School</label>
<select name = "searchsch" id = "sch" class = "sch" style = "width:400px">
<option value = "ALL"></option>
<?php $sth = $dbh->query("SELECT `root_id` root_id, `school_id`, `sch_name` schoolname,`sch_ch_name` school_ch_name FROM `school` WHERE `actived`=1 and`deleted`=0 group by `school_id`");
?>
<?php while ($ResultSet = $sth->fetch(PDO::FETCH_ASSOC)) { ?>
<option <?php
if (isset($_POST['go'])) {
if ($_POST['searchsch'] == $ResultSet['root_id']) {
?> selected="" <?php
}
}
?>value="<?= $ResultSet['root_id']; ?>"><?= $ResultSet['schoolname'] ?> | <?= $ResultSet['school_ch_name'] ?></option>
<?php } ?>
</select>
</div>
<?php
}
}
?>
</div>
</td>
<td>
<div class="pathways-inline-block">
<button class="btn" name="go" value="go" style="margin-left:30px" type="submit">Search</button>
</div>
</td>
</tr>
</table>
</form>
</div>
<?php
if (isset($_POST['go'])) {
if (isset($_POST['searchstun']) || isset($_POST['searchsch'])) {
$studentid;
$schoolid;
$countinvoice = 0;
if (isset($_POST['searchstun']) && $_POST['searchstun'] == 'ALL') {
echo "<script>alert('Please select a student')</script>";
} else
if (isset($_POST['searchsch']) && $_POST['searchsch'] == 'ALL') {
echo "<script>alert('Please select a school')</script>";
} else {
$query;
$Tdata = false;
if (isset($_POST['searchstun'])) {
$studentid = $_POST['searchstun'];
$schoolid = 'ALL';
} else {
$schoolid = $_POST['searchsch'];
$studentid = 'ALL';
}
if ($schoolid == 'ALL')
$query = "select root_id from invoice where deleted = 0 and stu_linking_id = '$studentid' ";
if ($studentid == 'ALL')
$query = "select root_id from invoice where deleted = 0 and school_id = '$schoolid' ";
$result = $dbh->query($query);
$result->setFetchMode(PDO::FETCH_OBJ);
while ($row = $result->fetch()) {
$Tdata = true;
}
?>
<form id="form" class="form-inline" action="" method="POST">
<?php if ($Tdata == true) { ?>
<?php
if ($schoolid == 'ALL')
$sth = $dbh->query("SELECT CONCAT(last_name, ' ', first_name) name,`ch_name`FROM `student` WHERE `actived`=1 and`deleted`=0 and `root_id` = $studentid group by `New_stu_ID`,`Sem_yr`");
if ($studentid == 'ALL')
$sth = $dbh->query("SELECT `sch_name` name,`sch_ch_name` school_ch_name FROM `school` WHERE `actived`=1 and`deleted`=0 and `root_id` = $schoolid group by `school_id`");
?>
<?php while ($ResultSet = $sth->fetch(PDO::FETCH_ASSOC)) { ?>
<input type='hidden' name='from_name' value='<?= $ResultSet['name'] ?>'>
<?php } ?>
<div class="container-fluid div-background">
<table>
<tr>
<td width="20%">Create By</td>
<td><input type='text' readonly="" value="<?= $_GET ? '' : $_SESSION['MIS_login']['username']; ?>"></td>
</tr>
<tr style="height: 15px"></tr>
<tr>
<td width="20%">Campus:</td>
<td><select name="campus" required="true">
<option></option>
<?php
$query = "Select campus_id,campus_name from campus";
$result = $dbh->query($query);
$result->setFetchMode(PDO::FETCH_OBJ);
while ($row = $result->fetch()) {
print '<option value=' . $row->campus_id . '>' . $row->campus_name . '</option>';
}
?>
</select>
</td>
<td width="5%"></td>
<!--td><label>Receipt From</label></td>
<td><input type="text" name="from_name" required=""></td-->
<td><label>Total Money</label>
</td><td><input type="text" name="total_fee" id="total_fee" required=""></td>
</tr>
<tr style="height: 15px"></tr>
<tr>
<td width="20%"><label>Type</label></td>
<td><select name="type">
<option value="0">Normal</option>
<option value="1">Community Chest</option>
</select></td>
<td width="5%"></td>
<td width="20%"><label>Date</label></td>
<td><div class="input-append date-picker">
<input id="start_date" class="dateISO" type="text" maxlength="200" data-format="yyyy-MM-dd" name="paydate" value="<?= $today ?>" style="width:90px" required>
<span class="add-on">
<i class="icon-calendar" data-date-icon="icon-calendar" data-time-icon="icon-time"></i>
</span>
</div></td>
</tr>
<tr style="height: 15px"></tr>
<tr>
<td width="20%">Pay Type</td>
<td><select name ="payway" id="payway">
<option value="0">By cash</option>
<option value="1">By cheque</option>
</select></td>
<!--td width="10%"><label>Bank Name</label></td>
<td><input type="text" name="bankname"></td>
<td width="10%">Cheque No</td>
<td><input type="text" name="cheque_no"></td-->
</tr>
<tr style="height: 15px"></tr>
<tbody id="paytype_tr">
<tr>
</tr>
</tbody>
<tr>
<!--td width="20%"><label>Payment of:</label></td>
<td><input type="text" name="payof"></td-->
</tr>
</table>
</div>
<table><tr style="height: 15px"></tr></table>
<?php } ?>
<table class="table table-striped table-bordered table-hover table-condensed" id="tablehead">
<thead>
<tr>
<th style="min-width:50px; width:5%"></th>
<th style="min-width:50px;">Invoice_Code</th>
<th style="min-width:50px;">Event_Code</th>
<th style="min-width:50px; width:10%">Total Amount</th>
<th style="min-width:50px; width:10%">Paid</th>
<th style="min-width:50px; width:10%">Pay</th>
</tr>
</thead>
<tbody>
<?php
$nopayed = true;
$payedsum = 0;
$allInvoicePayed = true;
//$query = "select receive_id, receive_code, is_normal from receive where deleted = 0 and invoice_id = 0 and receive_date between '$startdate' and '$enddate' ";
if ($schoolid == 'ALL')
$query = "select root_id, total_amount, invoice_code, event_code, invoice_date from invoice where deleted = 0 and stu_linking_id = '$studentid' ";
if ($studentid == 'ALL')
$query = "select root_id, total_amount, invoice_code, event_code, invoice_date from invoice where deleted = 0 and school_id = '$schoolid' ";
$result = $dbh->query($query);
$result->setFetchMode(PDO::FETCH_OBJ);
while ($row = $result->fetch()) {
$payed = $dbh->query("select sum(amount_paid) as payed from invoice_receipt where deleted = 0 and invoice_id = '$row->root_id' group by invoice_id");
$payed->setFetchMode(PDO::FETCH_OBJ);
while ($rowpayed = $payed->fetch()) {
$nopayed = false;
$payedsum = $rowpayed->payed;
}
if ($payedsum < $row->total_amount) {
$allInvoicePayed = false;
?>
<tr>
<td>
<input type="checkbox" name="selected_checked[]" id="selected_checked<?= $countinvoice ?>" value="<?= $countinvoice ?>">
<input type="hidden" name="selected_invoice[]" value="<?= $row->root_id ?>">
<input type="hidden" name="selected_event[]" value="<?= $row->event_code ?>">
<input type="hidden" name="selected_invoicedate" value="<?= $row->invoice_date ?>">
</td>
<td>
<input type="hidden" name="payof[]" value="<?= $row->invoice_code ?>" ><h5><?= $row->invoice_code ?></h5>
</td>
<td>
<h5><?= $row->event_code ?></h5>
</td>
<td>
<h5>$<?= $row->total_amount ?></h5>
<input type="hidden" name="invoice_total_amount[]" value="<?= $row->total_amount ?>" id="invoive_total_amount<?= $countinvoice ?>">
</td>
<td>
<?php
if ($nopayed == false) {
?>
<h5><?= $payedsum ?></h5>
<input type="hidden" name="invoice_payed[]" value="<?= $payedsum ?>" id="invoive_payed<?= $countinvoice ?>">
<?php
}
if ($nopayed == true) {
?>
<h5>0.00</h5>
<input type="hidden" name="invoice_payed[]" value="0" id="invoive_payed<?= $countinvoice ?>">
<?php } ?>
</td>
<td>
<input type="text" name="invoice_pay[]" id="invoive_pay<?= $countinvoice ?>" value="" style="width: 100px">
</td>
</tr>
<?php
$countinvoice++;
}
}
if ($allInvoicePayed == TRUE) {
?>
<tr><td colspan = "5"><h5>All Invoice Payed</h5></td></tr>
<?php
}
if ($Tdata == FALSE) {
?>
<tr><td colspan = "5"><h5>No invoice searched</h5></td></tr>
<?php } ?>
</tbody>
</table>
<div class="pathways-inline-block">
<a href="receipt_index.php" class="btn">Back</a>
</div>
<div class="pathways-inline-block">
<button class="btn" name="save" value="save" type="submit" style="margin-left:30px" >Save</button>
</div>
</form>
<?php
}
} else {
echo "<script>alert('Please select a search type!')</script>";
}
}
?>
</div> <!-- /container -->
</body>
</html>