Files
HotLunches/list.schools-with-old-invoices.php
T
2026-10-19 15:22:52 -07:00

70 lines
1.8 KiB
PHP

<?php
include "db.php";
$pYr = date("Y",time()) - 1;
$cYr = date("Y",time());
$nYr = date("Y",time()) + 1;
echo("\n");
$school_year = "$cYr/$nYr";
$x = readline("$school_year - Continue ");
$query = "SELECT * from invoice_header " .
"WHERE school_year != '$school_year' " .
"AND status = 'Open'";
$invoices = db_query($query);
$num = db_num_rows($invoices);
echo("$num Found\n");
$Schools = array();
while ($row = db_fetch_assoc($invoices)) {
extract($row);
$inum = $record_num;
$invoice_num = $inum + 500;
$school = db_getVal("SELECT * FROM schools WHERE record_num = $school_num");
$date = db_getVal("SELECT max(schedule_start_date) FROM hotlunch_schedules WHERE school_num = $school_num");
echo($school['school_name']." - #00$invoice_num ($date)\n");
$Schools[] = array($school['school_name'], $school_num, $inum, $invoice_num);
$query = "SELECT * FROM school_contact_list WHERE school_num = $school_num ORDER BY sequence";
$results = db_query($query);
while ($row = db_fetch_assoc($results)) {
extract($row);
echo(" - $contact_name $contact_email $contact_position\n");
}
echo("\n");
}
echo("\n");
$x = readline("Delete Invoices and Shutdown Schools - Continue ");
echo("\n");
$x = readline("This will delete the invoices - Continue ");
echo("\n");
$today = date("Y-m-d", time());
for ($i = 0; $i < count($Schools); $i++) {
$school_name = $Schools[$i][0];
$school_num = $Schools[$i][1];
$inum = $Schools[$i][2];
$invoice_num = $Schools[$i][3];
echo("$school_name - #00$invoice_num\n");
$query = "UPDATE schools SET status = 'Deleted', date_deleted = '$today' WHERE record_num = $school_num";
db_query($query);
$query = "UPDATE invoice_header SET status = 'Cancelled' WHERE record_num = $inum";
db_query($query);
}
?>