First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
require_once("include/globals.php");
|
||||
|
||||
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
||||
header("Location: /");
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Process all actions to list and edit records
|
||||
//
|
||||
$action = "order-payment-summary";
|
||||
$CurrentTable = "hotlunch_order_header";
|
||||
$FormFile = "";
|
||||
$TitleText = getLanguageText('TEXT-SCHEDULE-ORDER-PAYMENT-SUMMARY');
|
||||
|
||||
|
||||
|
||||
// Start the template and output buffering
|
||||
startTemplate();
|
||||
$templatePageTitle = $TitleText;
|
||||
|
||||
|
||||
|
||||
// Ensure that only valid user types have access to this module
|
||||
if (!in_array($_SESSION['UserInfo']['type'],array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team','Financial','Financial Team'))) {
|
||||
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
||||
header("Location: /?error_message=".urlencode($error_message));
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
$school_num = $school_record['record_num'];
|
||||
|
||||
|
||||
// View only selected schedules
|
||||
$swhere = "";
|
||||
$selected_schedules = array();
|
||||
if (array_key_exists('selected_schedules',$_POST) && $_POST['selected_schedules'] > 0) $selected_schedules = $_POST['selected_schedules'];
|
||||
if (count($selected_schedules) == 0 || (count($selected_schedules) == 1 && $selected_schedules[0] == 0)) {
|
||||
// Get set of schedules to display
|
||||
$results = db_query("SELECT distinct schedule_num,schedule_name FROM hotlunch_order_header AS hloh, hotlunch_schedules AS hs " .
|
||||
"WHERE hloh.school_num = $school_num " .
|
||||
"AND hs.school_num = $school_num " .
|
||||
"AND hloh.schedule_num = hs.record_num " .
|
||||
"AND (payment_method IS NOT NULL AND payment_method != '') " .
|
||||
"ORDER BY 2");
|
||||
$selected_schedules = array();
|
||||
while ($row = db_fetch_array($results)) {
|
||||
$selected_schedules[] = $row['schedule_num'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$message_width = 600;
|
||||
include "form.messages.php";
|
||||
|
||||
?>
|
||||
<br>
|
||||
<form method='post' name='transactions'>
|
||||
<table width='600' cellpadding='3' class='content-table'>
|
||||
<tr>
|
||||
<td align='right' valign='top'>Schedule: </td>
|
||||
<td align='left' valign='top'>
|
||||
<select name='selected_schedules[]' multiple size='6'>
|
||||
<option value='0' selected='selected'>All Schedules</option>
|
||||
<?php
|
||||
$end_date = date("Y-m-d",time() - 60 * 60 * 24 * 180);
|
||||
$query = "SELECT schedule_name,record_num FROM hotlunch_schedules " .
|
||||
"WHERE school_num = $school_num " .
|
||||
"AND schedule_type != 'Volunteer Only' " .
|
||||
"AND status != 'Deleted' " .
|
||||
"ORDER BY schedule_end_date DESC";
|
||||
$schedules = db_query($query);
|
||||
while ($row = db_fetch_array($schedules)) {
|
||||
$sname = $row['schedule_name'];
|
||||
$rnum = $row['record_num'];
|
||||
$selected = "";
|
||||
if (isset($schedule_num) && $schedule_num == $rnum) $selected = " selected='selected'";
|
||||
echo(" <option value='$rnum'$selected>$sname</option>\n");
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align='right' valign='top'></td>
|
||||
<td align='left' valign='top'><a href='#' class='btn btn--primary btn--xsmall' onClick='document.transactions.submit();'><span><?php displayLanguageText('TEXT-VIEW'); ?></span></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<input type='hidden' name='action' value='<?php echo($action) ?>'>
|
||||
<input type='hidden' name='naction' value='list'>
|
||||
</form>
|
||||
<?php
|
||||
|
||||
|
||||
//
|
||||
// Display order payment summary for schedule(s)
|
||||
//
|
||||
if (array_key_exists('naction',$_POST) && $_POST['naction'] == 'list') {
|
||||
|
||||
//
|
||||
// List all requested records
|
||||
//
|
||||
$columnHeaders = array(getLanguageText('TEXT-PAYMENT-METHOD'),
|
||||
getLanguageText('TEXT-COUNT'),
|
||||
"%",
|
||||
getLanguageText('TEXT-ORDER-TOTAL'),
|
||||
"%",
|
||||
getLanguageText('TEXT-AMOUNT-PAID'),
|
||||
"%"
|
||||
);
|
||||
$columnAlign = array('left','center','center','right','center','right','center');
|
||||
|
||||
for ($i = 0; $i < count($selected_schedules); $i++) {
|
||||
$schedule_num = $selected_schedules[$i];
|
||||
$schedule_name = db_getVal("SELECT schedule_name FROM hotlunch_schedules WHERE school_num = $school_num AND record_num = $schedule_num");
|
||||
if (!$schedule_name) continue;
|
||||
|
||||
// Reset amounts if needed
|
||||
$query = "UPDATE hotlunch_order_header SET amount_paid = order_total " .
|
||||
"WHERE school_num = $school_num " .
|
||||
"AND schedule_num = $schedule_num " .
|
||||
"AND status = 'Paid' " .
|
||||
"AND amount_paid > order_total";
|
||||
db_query($query);
|
||||
|
||||
$query = "UPDATE hotlunch_order_header SET amount_paid = 0 " .
|
||||
"WHERE school_num = $school_num " .
|
||||
"AND schedule_num = $schedule_num " .
|
||||
"AND status = 'Unpaid' " .
|
||||
"AND amount_paid > order_total";
|
||||
db_query($query);
|
||||
|
||||
echo("<center>\n");
|
||||
if ($i > 0) {
|
||||
echo("<p><br></p>");
|
||||
echo("<p><br></p>");
|
||||
}
|
||||
echo("<p><b>$schedule_name</b></p>\n");
|
||||
echo("</center>\n");
|
||||
|
||||
// Get totals first
|
||||
$query = "SELECT count(*) AS num, sum(order_total) AS total, sum(discount_amount) AS discount, sum(amount_paid) AS paid " .
|
||||
"FROM hotlunch_order_header " .
|
||||
"WHERE school_num = $school_num " .
|
||||
"AND schedule_num = $schedule_num " .
|
||||
"AND status NOT IN ('Inactive','Deleted','Concession')";
|
||||
$results = db_query($query);
|
||||
$row = db_fetch_array($results);
|
||||
$total_count = $row['num'];
|
||||
$total_orders = $row['total'];
|
||||
$total_paid = $row['paid'];
|
||||
|
||||
// Define Query
|
||||
$query = "SELECT payment_method, count(*) AS num, sum(order_total) AS total, sum(discount_amount) AS discount, sum(amount_paid) AS paid " .
|
||||
"FROM hotlunch_order_header " .
|
||||
"WHERE school_num = $school_num " .
|
||||
"AND schedule_num = $schedule_num " .
|
||||
"AND status NOT IN ('Inactive','Deleted','Concession','Complimentary','Pending') " .
|
||||
"GROUP BY 1 " .
|
||||
"ORDER BY 1";
|
||||
echo("<!-- QUERY: $query -->\n");
|
||||
$summary = db_query($query);
|
||||
|
||||
|
||||
// Format the data
|
||||
$data = array();
|
||||
$totals = array('',0,'',0,'',0,'');
|
||||
$count = 0;
|
||||
$psnum = 0;
|
||||
while ($row = db_fetch_array($summary)) {
|
||||
$payment_method = $row['payment_method'];
|
||||
//if (strlen($payment_method) == 0) {
|
||||
// if ($row['status'] == 'Unpaid') $payment_method = 'Unpaid Orders';
|
||||
// if ($row['status'] == 'Paid') $payment_method = 'Unknown';
|
||||
//}
|
||||
if (strlen($payment_method) == 0) $payment_method = 'Unknown';
|
||||
|
||||
$data[$count][0] = $payment_method;
|
||||
$data[$count][1] = $row['num'];
|
||||
$data[$count][2] = ($total_count == 0) ? 0 : sprintf("%.1f",round($row['num'] / $total_count * 1000) / 10) . '%';
|
||||
$data[$count][3] = $currencySymbol . number_format($row['total'],2);
|
||||
$data[$count][4] = ($total_orders == 0) ? 0 : sprintf("%.1f",round($row['total'] / $total_orders * 1000) / 10) . '%';
|
||||
$data[$count][5] = $currencySymbol . number_format($row['paid'],2);
|
||||
$data[$count][6] = ($total_paid == 0) ? 0 : sprintf("%.1f",round($row['paid'] / $total_paid * 1000) / 10) . '%';
|
||||
|
||||
$totals[1] += $row['num'];
|
||||
$totals[3] += $row['total'];
|
||||
$totals[5] += $row['paid'];
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
// Format the totals
|
||||
$totals[3] = $currencySymbol . number_format($totals[3],2);
|
||||
$totals[5] = $currencySymbol . number_format($totals[5],2);
|
||||
|
||||
$default_data_width = 600;
|
||||
$display_dataset_count = 'N';
|
||||
listDataCustom($data,$columnHeaders,$action,array(),'N',$columnAlign,$totals);
|
||||
|
||||
}
|
||||
|
||||
$snums = implode(',',$selected_schedules);
|
||||
?>
|
||||
<center>
|
||||
<table cellpadding='5'>
|
||||
<tr>
|
||||
<td align='center'><a href='?action=order-payment-summary-report&selected_schedules=<?php echo($snums) ?>' class='btn btn--primary btn--xsmall'><span><?php displayLanguageText('TEXT-PRINT') ?></span></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
<?php
|
||||
}
|
||||
|
||||
endTemplate();
|
||||
?>
|
||||
Reference in new issue
Block a user