First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
@@ -0,0 +1,496 @@
|
||||
<?php
|
||||
require_once("include/globals.php");
|
||||
|
||||
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
||||
header("Location: /");
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
// Start the template and output buffering
|
||||
startTemplate();
|
||||
$templatePageTitle = "";
|
||||
$headerArgs = "";
|
||||
|
||||
$moduleName = "supplier_orders.php";
|
||||
// startLog($moduleName);
|
||||
|
||||
|
||||
|
||||
// Ensure that only valid user types have access to this module
|
||||
$AllowedUserTypes = array('SuperUser','System Administrator','Application Administrator','Application Volunteer','Schedule Volunteer','Administration Team','Schedule Team','Supplier','Financial Team','Schedule Reporting');
|
||||
if (checkPermission($AllowedUserTypes) != 1) {
|
||||
echo("<br>\n");
|
||||
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
||||
include "form.messages.php";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Process all actions to list and edit records
|
||||
//
|
||||
$naction = "";
|
||||
|
||||
$CurrentTable = "supplier_order_header";
|
||||
$DeleteField = "";
|
||||
$dSeparator = "";
|
||||
$FormFile = "supplier_orders.form.php";
|
||||
$TitleText = "Supplier Order";
|
||||
$OrderBy = "";
|
||||
$Sequence = 'N';
|
||||
|
||||
|
||||
if (array_key_exists('schedule_num',$_GET)) $schedule_num = intval($_GET['schedule_num']);
|
||||
if (array_key_exists('schedule_num',$_POST)) $schedule_num = intval($_POST['schedule_num']);
|
||||
|
||||
if (array_key_exists('menu_num',$_GET)) $menu_num = intval($_GET['menu_num']);
|
||||
if (array_key_exists('menu_num',$_POST)) $menu_num = intval($_POST['menu_num']);
|
||||
|
||||
if (!isset($schedule_num)) {
|
||||
$error_message = getLanguageText('ERRORMSG-INVALID-SCHEDULE-NUM');
|
||||
$action = '';
|
||||
$naction = '';
|
||||
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
||||
exit();
|
||||
}
|
||||
|
||||
$headerArgs = "&schedule_num=$schedule_num";
|
||||
|
||||
if (!isset($menu_num)) {
|
||||
$error_message = getLanguageText('ERRORMSG-NO-MENU-NUM');
|
||||
$action = 'schedule-reports';
|
||||
$naction = '';
|
||||
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
// Check if this is a valid schedule
|
||||
$swhere = "";
|
||||
// if ($_SESSION['UserInfo']['type'] == 'Supplier') $swhere = " and supplier_num = " . $_SESSION['UserInfo']['supplier_num'];
|
||||
$query = "select * from hotlunch_schedules " .
|
||||
"where school_num = $school_num " .
|
||||
"and record_num = $schedule_num " .
|
||||
$swhere;
|
||||
writeLog($query);
|
||||
$results = db_query($query);
|
||||
|
||||
if (db_num_rows($results) == 0) {
|
||||
$error_message = getLanguageText('ERRORMSG-INVALID-SCHEDULE');
|
||||
$action = 'schedule-reports';
|
||||
$naction = '';
|
||||
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
||||
exit();
|
||||
}
|
||||
|
||||
$hotlunch_schedule = db_fetch_array($results);
|
||||
|
||||
|
||||
// Check if this is a valid menu
|
||||
$query = "select * from hotlunch_menu_dates " .
|
||||
"where school_num = $school_num " .
|
||||
"and schedule_num = $schedule_num " .
|
||||
"and record_num = $menu_num";
|
||||
writeLog($query);
|
||||
$results = db_query($query);
|
||||
|
||||
if (db_num_rows($results) == 0) {
|
||||
echo("<br>\n");
|
||||
$error_message = "The requested hot lunch menu is invalid";
|
||||
include "form.messages.php";
|
||||
return;
|
||||
}
|
||||
|
||||
$hotlunch_menu_date = db_fetch_array($results);
|
||||
$delivery_date = $hotlunch_menu_date['menu_date'];
|
||||
$menu_title = $hotlunch_menu_date['menu_title'];
|
||||
|
||||
if (is_null($delivery_date) || strlen($delivery_date) == 0) $delivery_date = $hotlunch_schedule['end_order_date'];
|
||||
|
||||
|
||||
//
|
||||
// Update table values - re-post quantities
|
||||
//
|
||||
include "supplier_orders.post.php";
|
||||
|
||||
$templatePageTitle = getLanguageText('TEXT-SUPPLIER-ORDERS-AND-TOTALS') . " - $menu_title";
|
||||
|
||||
|
||||
if (array_key_exists('naction',$_GET)) $naction = $_GET['naction'];
|
||||
if (array_key_exists('naction',$_POST)) $naction = $_POST['naction'];
|
||||
|
||||
$school_num = $school_record['record_num'];
|
||||
|
||||
|
||||
switch (strtolower($naction)) {
|
||||
|
||||
case "update":
|
||||
$PostCopy = $_POST;
|
||||
$hotlunch_menu_transactions = new Table("hotlunch_menu_transactions");
|
||||
|
||||
foreach ($_POST as $key => $val) {
|
||||
// Process actual charges values for supplier order items
|
||||
if (strpos($key,"actual") === 0) {
|
||||
list($nn,$rnum) = explode('_',$key);
|
||||
$val = str_replace('$','',$val);
|
||||
$val = str_replace(',','',$val);
|
||||
$val = str_replace('..','.',$val);
|
||||
if (strlen($val) == 0) $val = 0;
|
||||
|
||||
// Get supplier_order_items record
|
||||
$menu_num = intval($_POST["menu_$rnum"]);
|
||||
$supplier_num = intval($_POST["supplier_$rnum"]);
|
||||
$supplier_product_num = intval($_POST["product_$rnum"]);
|
||||
|
||||
$query = "INSERT INTO supplier_order_items_actual (school_num,schedule_num,menu_num,supplier_num,supplier_product_num,actual_cost) " .
|
||||
"VALUES ($school_num,$schedule_num,$menu_num,$supplier_num,$supplier_product_num,$val) " .
|
||||
"ON DUPLICATE KEY UPDATE actual_cost = $val";
|
||||
writeLog($query);
|
||||
db_query($query);
|
||||
}
|
||||
|
||||
// Update existing menu date transactions
|
||||
if (strpos($key,"description_") === 0) {
|
||||
list($nn,$rnum) = explode('_',$key);
|
||||
$description = $val;
|
||||
$type = $_POST["type_$rnum"];
|
||||
$amount = str_replace('$','',$_POST["amount_$rnum"]);
|
||||
$amount = str_replace(',','',$amount);
|
||||
if (strlen($amount) == 0) $amount = 0;
|
||||
$record_num = $rnum;
|
||||
|
||||
// Update the record if there is a description
|
||||
if (strlen($description)) {
|
||||
$query = $hotlunch_menu_transactions->BuildUpdate();
|
||||
db_query($query);
|
||||
}
|
||||
else {
|
||||
$query = "delete from hotlunch_menu_transactions where record_num = $record_num";
|
||||
db_query($query);
|
||||
}
|
||||
}
|
||||
|
||||
// Insert new menu date transactions
|
||||
if (strpos($key,"new_description_") === 0) {
|
||||
list($n1,$n2,$rnum) = explode('_',$key);
|
||||
$description = $val;
|
||||
$type = $_POST["new_type_$rnum"];
|
||||
$amount = str_replace('$','',$_POST["new_amount_$rnum"]);
|
||||
$amount = str_replace(',','',$amount);
|
||||
|
||||
if (strlen($description) > 0 && strlen($amount) > 0) {
|
||||
$query = $hotlunch_menu_transactions->BuildInsert();
|
||||
writeLog($query);
|
||||
db_query($query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$query = "select supplier_num,sum(actual_cost) as actual_cost from supplier_order_items_actual " .
|
||||
"where school_num = $school_num " .
|
||||
"and schedule_num = $schedule_num " .
|
||||
"and menu_num = $menu_num " .
|
||||
"group by 1";
|
||||
writeLog($query);
|
||||
$results = db_query($query);
|
||||
|
||||
while ($row = db_fetch_array($results)) {
|
||||
$supplier_num = $row['supplier_num'];
|
||||
$actual_cost = $row['actual_cost'];
|
||||
|
||||
$query = "update supplier_order_header " .
|
||||
"set actual_total = $actual_cost " .
|
||||
"where school_num = $school_num " .
|
||||
"and supplier_num = $supplier_num";
|
||||
writeLog($query);
|
||||
db_query($query);
|
||||
}
|
||||
|
||||
// Calculate net total for this menu date
|
||||
$query = "select sum(actual_cost) as amount from supplier_order_items_actual " .
|
||||
"where school_num = $school_num " .
|
||||
"and schedule_num = $schedule_num " .
|
||||
"and menu_num = $menu_num";
|
||||
writeLog($query);
|
||||
$results = db_query($query);
|
||||
$row = db_fetch_array($results);
|
||||
$supplier_costs = sprintf("%0.2f",$row['amount']);
|
||||
|
||||
// Get misc expenses
|
||||
$query = "select sum(amount) as amount from hotlunch_menu_transactions " .
|
||||
"where school_num = $school_num " .
|
||||
"and schedule_num = $schedule_num " .
|
||||
"and menu_num = $menu_num " .
|
||||
"and type = 'Expense'";
|
||||
writeLog($query);
|
||||
$results = db_query($query);
|
||||
$row = db_fetch_array($results);
|
||||
$other_costs = sprintf("%0.2f",$row['amount']);
|
||||
|
||||
// Get misc revenue
|
||||
$query = "select sum(amount) as amount from hotlunch_menu_transactions " .
|
||||
"where school_num = $school_num " .
|
||||
"and schedule_num = $schedule_num " .
|
||||
"and menu_num = $menu_num " .
|
||||
"and type = 'Revenue'";
|
||||
writeLog($query);
|
||||
$results = db_query($query);
|
||||
$row = db_fetch_array($results);
|
||||
$other_revenue = sprintf("%0.2f",$row['amount']);
|
||||
|
||||
// Get order items revenue
|
||||
$query = "select sum(extended_price) as amount from hotlunch_order_items " .
|
||||
"where school_num = $school_num " .
|
||||
"and schedule_num = $schedule_num " .
|
||||
"and menu_num = $menu_num " .
|
||||
"and ordered_by_type != 'Concession' " .
|
||||
"and active != 'N'";
|
||||
writeLog($query);
|
||||
$results = db_query($query);
|
||||
$row = db_fetch_array($results);
|
||||
$order_revenue = sprintf("%0.2f",$row['amount']);
|
||||
|
||||
$net_revenue = $order_revenue + $other_revenue - $supplier_costs - $other_costs;
|
||||
|
||||
// Update hotlunch_menu_dates
|
||||
$query = "update hotlunch_menu_dates " .
|
||||
"set order_revenue = $order_revenue, " .
|
||||
"other_revenue = $other_revenue, " .
|
||||
"supplier_costs = $supplier_costs, " .
|
||||
"other_costs = $other_costs, " .
|
||||
"net_revenue = $net_revenue " .
|
||||
"where school_num = $school_num " .
|
||||
"and schedule_num = $schedule_num " .
|
||||
"and record_num = $menu_num";
|
||||
writeLog($query);
|
||||
db_query($query);
|
||||
|
||||
|
||||
$form_message = "Supplier Orders Have Been Updated";
|
||||
$naction = "list";
|
||||
break;
|
||||
|
||||
default:
|
||||
$naction = "list";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// List all records if naction is "list"
|
||||
//
|
||||
if ($naction == "list") {
|
||||
|
||||
include "hotlunch_reports.menu.php";
|
||||
echo("<br>\n");
|
||||
|
||||
$message_width = 900;
|
||||
include "form.messages.php";
|
||||
|
||||
// Get supplier order records for display
|
||||
if ($supplier_school_num == 0) $supplier_school_num = $school_num;
|
||||
$query = "select supplier_name,product_name,soh.supplier_num," .
|
||||
"online_qty,supplier_product_qty,soi.package_qty,qty_ordered,estimated_cost,soi.actual_cost,soi.record_num,sp.record_num AS supplier_product_num " .
|
||||
"from supplier_order_header as soh, supplier_order_items as soi , suppliers as s, supplier_products as sp " .
|
||||
"where soh.school_num = $school_num " .
|
||||
"and soi.school_num = $school_num " .
|
||||
"and s.school_num = $supplier_school_num " .
|
||||
"and sp.school_num = $supplier_school_num " .
|
||||
"and soi.order_num = soh.record_num " .
|
||||
"and soh.supplier_num = s.record_num " .
|
||||
"and soh.schedule_num = $schedule_num " .
|
||||
"and soh.menu_num = $menu_num " .
|
||||
"and soi.supplier_product_num = sp.record_num " .
|
||||
"order by 1,2";
|
||||
writeLog($query);
|
||||
$results = db_query($query);
|
||||
|
||||
|
||||
// Get misc charges for display
|
||||
$query = "select * from hotlunch_menu_transactions " .
|
||||
"where school_num = $school_num " .
|
||||
"and schedule_num = $schedule_num " .
|
||||
"and menu_num = $menu_num " .
|
||||
"order by type,description";
|
||||
writeLog($query);
|
||||
$results2 = db_query($query);
|
||||
|
||||
$count = 0;
|
||||
|
||||
$query = "select * from hotlunch_schedules " .
|
||||
"where school_num = $school_num " .
|
||||
"and record_num = $schedule_num";
|
||||
writeLog($query);
|
||||
$hotlunch_schedule = db_getVal($query);
|
||||
|
||||
?>
|
||||
<form method='post' action='/'>
|
||||
<table width='900' cellpadding='3' cellspacing='1' border='0' class='content-table'>
|
||||
<tr>
|
||||
<td align='left' colspan='7' class='heading'>
|
||||
<h2><?php echo($hotlunch_schedule['schedule_name']) ?> - <?php echo("$menu_title - $delivery_date") ?></h2>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
// Column headers for supplier orders
|
||||
if (db_num_rows($results) > 0) {
|
||||
?>
|
||||
<tr>
|
||||
<td align='left' class='heading'><?php displayLanguageText('TEXT-SUPPLIER'); ?></td>
|
||||
<td align='left' class='heading'><?php displayLanguageText('TEXT-PRODUCT'); ?></td>
|
||||
<td width='50' class='heading' align='center'><?php displayLanguageText('TEXT-ORDERED'); ?></td>
|
||||
<td width='50' class='heading' align='center'><?php displayLanguageText('TEXT-PACKAGE'); ?></td>
|
||||
<td width='50' class='heading' align='center'><?php displayLanguageText('TEXT-UNITS'); ?></td>
|
||||
<td width='80' class='heading' align='right'><?php displayLanguageText('TEXT-ESTIMATED'); ?></td>
|
||||
<td width='80' class='heading' align='right'><?php displayLanguageText('TEXT-ACTUAL'); ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
// Process each supplier order record
|
||||
while ($row = db_fetch_array($results)) {
|
||||
extract($row);
|
||||
|
||||
$bgclass = "data-even";
|
||||
if ($count % 2) $bgclass = "data-odd";
|
||||
$count++;
|
||||
|
||||
$afname = "actual_$record_num";
|
||||
$supplier_order_link = "<a href='?action=supplier-orders-print&schedule_num=$schedule_num&menu_num=$menu_num&supplier_num=$supplier_num'>" .
|
||||
"$supplier_name</a>";
|
||||
|
||||
$mfname = "menu_$record_num";
|
||||
$sfname = "supplier_$record_num";
|
||||
$pfname = "product_$record_num";
|
||||
|
||||
$actual_cost = db_getVal("SELECT actual_cost FROM supplier_order_items_actual " .
|
||||
"WHERE school_num = $school_num " .
|
||||
"AND schedule_num = $schedule_num " .
|
||||
"AND menu_num = $menu_num " .
|
||||
"AND supplier_num = $supplier_num " .
|
||||
"AND supplier_product_num = $supplier_product_num");
|
||||
if ($actual_cost == '') $actual_cost = $estimated_cost;
|
||||
|
||||
?>
|
||||
<tr class='<?php echo($bgclass) ?>'>
|
||||
<td align='left' ><?php echo($supplier_order_link) ?></td>
|
||||
<td align='left'><?php echo($product_name) ?></td>
|
||||
<td align='center'><?php echo(number_format($online_qty,0)) ?></td>
|
||||
<td align='center'><?php echo($package_qty) ?></td>
|
||||
<td align='center'><?php echo($qty_ordered) ?></td>
|
||||
<td align='right'><?php echo($currencySymbol . number_format($estimated_cost,2)) ?></td>
|
||||
<td align='right'><input type='text' name='<?php echo($afname) ?>' value='<?php echo($currencySymbol . number_format($actual_cost,2)) ?>' est='<?php echo(number_format($estimated_cost,2)) ?>' size='8' style='text-align: right; float: right;' class='actual-cost'></td>
|
||||
<input type='hidden' name='<?php echo($mfname) ?>' value='<?php echo($menu_num) ?>'>
|
||||
<input type='hidden' name='<?php echo($sfname) ?>' value='<?php echo($supplier_num) ?>'>
|
||||
<input type='hidden' name='<?php echo($pfname) ?>' value='<?php echo($supplier_product_num) ?>'>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ($count > 0) {
|
||||
?>
|
||||
<tr>
|
||||
<td colspan='7'> </td>
|
||||
</tr>
|
||||
<?php
|
||||
|
||||
// Column headers for miscellaneous charges and revenue
|
||||
?>
|
||||
<tr>
|
||||
<td align='left' colspan='7' class='heading'><h2><?php displayLanguageText('TEXT-OTHER-CHARGES-AND-REVENUE'); ?> - <?php echo("$menu_title - $delivery_date") ?></h2></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align='center' colspan='2' class='heading'><?php displayLanguageText('TEXT-DESCRIPTION'); ?> <span class='small'>(<?php displayLanguageText('TEXT-LEAVE-BLANK-TO-DELETE-A-ROW'); ?>)</span></td>
|
||||
<td align='center' colspan='4' class='heading'><?php displayLanguageText('TEXT-TYPE'); ?></td>
|
||||
<td width='80' class='heading' align='right'><?php displayLanguageText('TEXT-AMOUNT'); ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
|
||||
if (db_num_rows($results2) > 0) {
|
||||
// Process each menu date transaction record
|
||||
while ($row = db_fetch_array($results2)) {
|
||||
extract($row);
|
||||
|
||||
$bgclass = "data-even";
|
||||
if ($count % 2) $bgclass = "data-odd";
|
||||
$count++;
|
||||
|
||||
$dname = "description_$record_num";
|
||||
$tname = "type_$record_num";
|
||||
$aname = "amount_$record_num";
|
||||
?>
|
||||
<tr class='<?php echo($bgclass) ?>'>
|
||||
<td align='center' colspan='2'><input type='text' name='<?php echo($dname) ?>' value='<?php echo($description) ?>' size='90'></td>
|
||||
<td align='center' colspan='4'><?php BuildFileRadio("misc_types.txt",$tname,$type) ?></td>
|
||||
<td align='right'><input type='text' name='<?php echo($aname) ?>' value='<?php echo($currencySymbol . number_format($amount,2)) ?>' size='8' style='text-align: right; float: right;'></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
$bgclass = "data-even";
|
||||
if ($count % 2) $bgclass = "data-odd";
|
||||
$count++;
|
||||
|
||||
$dname = "new_description_$i";
|
||||
$tname = "new_type_$i";
|
||||
$aname = "new_amount_$i";
|
||||
$type = "Expense";
|
||||
?>
|
||||
<tr class='<?php echo($bgclass) ?>'>
|
||||
<td align='center' colspan='2'><input type='text' name='<?php echo($dname) ?>' size='90'></td>
|
||||
<td align='center' colspan='4'><?php BuildFileRadio("misc_types.txt",$tname,$type) ?></td>
|
||||
<td align='right'><input type='text' name='<?php echo($aname) ?>' size='8' style='text-align: right; float: right;'></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<br>
|
||||
<input type='submit' class='btn btn--primary' value="<?php displayLanguageText('TEXT-UPDATE-TOTALS'); ?>">
|
||||
<input type='hidden' name='action' value='supplier-orders'>
|
||||
<input type='hidden' name='naction' value='update'>
|
||||
<input type='hidden' name='schedule_num' value='<?php echo($schedule_num) ?>'>
|
||||
<input type='hidden' name='menu_num' value='<?php echo($menu_num) ?>'>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
// If the menu_num is set then get the schedule number
|
||||
if (isset($menu_num)) {
|
||||
$query = "select schedule_num from hotlunch_menu_dates where record_num = $menu_num";
|
||||
$schedule_num = db_getVal($query);
|
||||
}
|
||||
|
||||
?>
|
||||
<table width='600' cellpadding='2' cellspacing='2' border='0'>
|
||||
<tr>
|
||||
<td align='center'><a href='#' id='apply-estimated' class='btn btn--primary>'><?php displayLanguageText('TEXT-APPLY-ESTIMATED'); ?></a></td>
|
||||
<td align='center'><a href='?action=supplier-orders-print&schedule_num=<?php echo($schedule_num) ?>&menu_num=<?php echo($menu_num) ?>' class='btn btn--primary>'><?php displayLanguageText('TEXT-SUPPLIER-ORDERS'); ?></a></td>
|
||||
<td align='center'><a href='?action=supplier-orders-print-summary&schedule_num=<?php echo($schedule_num) ?>&menu_num=<?php echo($menu_num) ?>' class='btn btn--primary>'><?php displayLanguageText('TEXT-SUPPLIER-SUMMARY'); ?></a></td>
|
||||
<td align='center'><a href='?action=menu-date-print-totals&schedule_num=<?php echo($schedule_num) ?>&menu_num=<?php echo($menu_num) ?>' class='btn btn--primary>'><?php displayLanguageText('TEXT-PRINT-TOTALS'); ?></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$("#apply-estimated").click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$(".actual-cost").each(function(i,obj) {
|
||||
var est = $(this).attr('est');
|
||||
$(this).val(est);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php
|
||||
include "hotlunch_orders.print_buttons.php";
|
||||
|
||||
endTemplate();
|
||||
?>
|
||||
Reference in new issue
Block a user