📄 payment.php
字号:
<?php
// +-------------------------------------------------------------+
// | DeskPRO v [2.0.1 Production]
// | Copyright (C) 2001 - 2004 Headstart Solutions Limited
// | Supplied by WTN-WDYL
// | Nullified by WTN-WDYL
// | Distribution via WebForum, ForumRU and associated file dumps
// +-------------------------------------------------------------+
// | DESKPRO IS NOT FREE SOFTWARE
// +-------------------------------------------------------------+
// | License ID : Full Enterprise License =) ...
// | License Owner : WTN-WDYL Team
// +-------------------------------------------------------------+
// | $RCSfile: payment.php,v $
// | $Date: 2004/02/10 01:34:25 $
// | $Revision: 1.31 $
// +-------------------------------------------------------------+
// | File Details:
// | - Billables/payables report generator (administration interface)
// +-------------------------------------------------------------+
error_reporting(E_ALL & ~E_NOTICE);
require_once('./global.php');
//Nullify WTN-WDYL Team
include('./settings_include.php');
feature_check('payments');
############################### UPDATE SETTINGS ###############################
if ($_REQUEST['do'] == "update") {
update_settings();
$_REQUEST['do'] = "settings";
}
############################### DISPLAY SETTINGS ###############################
if ($_REQUEST['do'] == "settings") {
admin_header('Payment Functions', 'Payment Settings');
show_settings('payment.php', array('Payment Settings'), false);
exit;
}
############################### RUN PAYMENT REPORTS ###############################
admin_header('Payment Functions', 'Run Payment Reports');
if ($_REQUEST['submit'] AND $_REQUEST['ids']) {
$ids = explode(',',$_REQUEST['ids']);
$queries = 0;
if (is_array($_REQUEST['isbillable'])) {
$sql_billable = array_intersect($ids, $_REQUEST['isbillable']);
$sql_unbillable = array_diff($ids, $_REQUEST['isbillable']);
} else {
$sql_unbillable = $ids;
}
if (is_array($_REQUEST['ispaid'])) {
$sql_paid = array_intersect($ids, $_REQUEST['ispaid']);
$sql_unpaid = array_diff($ids, $_REQUEST['ispaid']);
} else {
$sql_unpaid = $ids;
}
if (is_array($sql_billable)) {
if (count($sql_billable)) {
$db->query('UPDATE user_bill SET billable = 1 WHERE id IN ' . array2sql($sql_billable));
$queries++;
}
}
if (is_array($sql_unbillable)) {
if (count($sql_unbillable)) {
$db->query('UPDATE user_bill SET billable = 0 WHERE id IN ' . array2sql($sql_unbillable));
$queries++;
}
}
if (is_array($sql_paid)) {
if (count($sql_paid)) {
$db->query('UPDATE user_bill SET paid = 1 WHERE id IN ' . array2sql($sql_paid));
$queries++;
}
}
if (is_array($sql_unpaid)) {
if (count($sql_unpaid)) {
$db->query('UPDATE user_bill SET paid = 0 WHERE id IN ' . array2sql($sql_unpaid));
$queries++;
}
}
}
$ids = array();
$ticketid = (int)$_REQUEST['ticketid'];
$paid = (int)$_REQUEST['paid'];
if ($_REQUEST['bytech']) {
$group = 'techname';
} else {
$group = 'username';
}
if (!(int)$_REQUEST['billable']) {
$billable = 1;
} else {
$billable = (int)$_REQUEST['billable'];
}
$detail = (int)$_REQUEST['detail'];
if ($ticketid) { // If a specific ticket is requested, we're doing a detailed view
$detail = 1;
}
$ystart = (int)$_REQUEST['ystart'];
$mstart = (int)$_REQUEST['mstart'];
$dstart = (int)$_REQUEST['dstart'];
$yend = (int)$_REQUEST['yend'];
$mend = (int)$_REQUEST['mend'];
$dend = (int)$_REQUEST['dend'];
$start = validate_ymd("$ystart-$mstart-$dstart");
$end = validate_ymd("$yend-$mend-$dend");
$stamp = time();
$now = split('-', date('Y-m-d', $stamp));
if (!$start) { // Default to starting at the beginning of the current month
$start = strtotime("$now[0]-$now[1]-01");
} else {
$start = strtotime($start);
}
if (!$end OR $_REQUEST['alldates']) { // Default to ending right now
$end = $stamp;
} else {
$end = strtotime($end) + ((60 * 60 * 24) - 1);
}
if ($_REQUEST['alldates']) { // If we've been asked to do everything, start should be zero
$start = 0;
}
if ($settings['log_to_billing']) {
$notes[] = '<B>Note:</B> Automatic billing is <I>not</I> enabled; results may be incomplete.';
}
if ($settings['payments']) {
$notes[] = '<B>Warning:</B> Payments are not currently enabled; results may be incomplete.';
}
if (is_array($notes)) {
$notes = join('<BR>', $notes);
}
if (is_array($_REQUEST['userid'])) {
if (!in_array(0, $_REQUEST['userid'])) {
$db->query('SELECT id FROM user WHERE id IN ' . array2sql($_REQUEST['userid']));
while ($res = $db->row_array()) {
$validusers[] = $res['id'];
}
$invalidusers = array_diff($_REQUEST['userid'], $validusers);
if (count($invalidusers)) {
$warnings[] = 'User(s) not valid: ' . join(', ', $invalidusers);
}
$terms[] = 'user_bill.userid in ' . array2sql($_REQUEST['userid']);
if (count($validuser)) {
$criteria[] = 'user ID(s) ' . join(', ', $validusers);
}
}
}
if (is_array($_REQUEST['techid'])) {
if (!in_array(0, $_REQUEST['techid'])) {
$db->query('SELECT id FROM tech WHERE id IN ' . array2sql($_REQUEST['techid']));
while ($res = $db->row_array()) {
$validtechs[] = $res['id'];
}
$invalidtechs = array_diff($_REQUEST['techid'], $validtechs);
if (count($invalidtechs)) {
$warnings[] = 'Tech(s) not valid: ' . join(', ', $invalidtechs);
}
$terms[] = 'user_bill.techid in ' . array2sql($_REQUEST['techid']);
$criteria[] = 'technician ID(s) ' . join(', ', $validtechs);
}
}
if ($ticketid) {
$db->query("SELECT id FROM ticket WHERE id = $ticketid");
if ($db->num_rows()) {
$terms[] = "user_bill.ticketid = $ticketid";
$criteria[] = "ticket #$ticketid";
} else {
$warnings[] = "Ticket $ticketid couldn't be found.";
}
}
if ($billable == 1) { // Billable = 0, show non-billable. Billable = 1, show billable. Billable = anything else, show both
$terms[] = 'billable';
$criteria[] = 'billable';
} elseif ($billable == 0) {
$terms[] = '!billable';
$criteria[] = 'non-billable';
} else {
$billable = 2;
$criteria[] = 'billable and non-billable';
}
if ($paid == 1) { // Paid = 0, show unpaid. Paid = 1, show paid. Paid = anything else, show all
$terms[] = 'paid';
$criteria[] = 'paid';
} elseif ($paid == 0) {
$terms[] = '!paid';
$criteria[] = 'unpaid';
} else {
$paid = 2;
$criteria[] = 'paid and unpaid';
}
$terms[] = "stamp >= $start";
$terms[] = "stamp <= $end";
if ($start) {
$criteria[] = date('F jS Y', $start) . ' to ' . date('F jS Y', $end);
} else {
$criteria[] = 'all dates';
}
if (is_array($terms)) {
$where = join(' AND ', $terms);
}
if ($detail) {
$criteria[] = '<I>detail view</I>';
$query = "SELECT user_bill.id, time, charge, user.username, user.id AS userid, tech.username AS techname, tech.id AS techid, ticket.id as ticketid, stamp, paid, billable
FROM user_bill
LEFT JOIN user ON user_bill.userid = user.id
LEFT JOIN ticket ON user_bill.ticketid = ticket.id
LEFT JOIN tech ON user_bill.techid = tech.id
WHERE $where
ORDER BY username, stamp";
} else {
$criteria[] = '<I>summary view</I>';
$query = "SELECT SUM(time) AS time, SUM(charge) AS charge, user.username, user.id AS userid, tech.username AS techname, tech.id AS techid, ticket.id as ticketid, stamp, paid, billable, ticketid
FROM user_bill
LEFT JOIN user ON user_bill.userid = user.id
LEFT JOIN ticket ON user_bill.ticketid = ticket.id
LEFT JOIN tech ON user_bill.techid = tech.id
WHERE $where
GROUP BY $group
ORDER BY username, stamp";
}
$db->query($query);
$total = 0;
if ($detail) {
if ($db->num_rows()) {
$paid_js = ' (<A HREF="javascript:checkall(document.forms[\'res\'].elements[\'ispaid[]\']);">All</A> <A HREF="javascript:uncheckall(document.res.elements[\'ispaid[]\']);">None</A>)';
$bill_js = ' (<A HREF="javascript:checkall(document.forms[\'res\'].elements[\'isbillable[]\']);">All</A> <A HREF="javascript:uncheckall(document.res.elements[\'isbillable[]\']);">None</A>)';
} else {
$paid_js = '';
$bill_js = '';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -