164 lines
3.8 KiB
PHP
164 lines
3.8 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
require_once("include/globals.php");
|
|
|
|
$configuration = $school_record['system_configuration'];
|
|
$currMonth = date("m",time());
|
|
|
|
$pYr = date("Y",time()) - 1;
|
|
$cYr = date("Y",time());
|
|
$nYr = date("Y",time()) + 1;
|
|
|
|
$prorate = 0;
|
|
|
|
switch ($currMonth) {
|
|
case '01':
|
|
$school_year = "$pYr/$cYr";
|
|
$renewal_date = $cYr . "-08-01";
|
|
$prorate = 30;
|
|
break;
|
|
|
|
case '02':
|
|
case '03':
|
|
case '04':
|
|
case '05':
|
|
case '06':
|
|
case '07':
|
|
case '08':
|
|
case '09':
|
|
case '10':
|
|
case '11':
|
|
case '12':
|
|
$school_year = "$cYr/$nYr";
|
|
$renewal_date = $nYr . "-08-01";
|
|
break;
|
|
|
|
case 'NA':
|
|
$school_year = "$cYr/$nYr";
|
|
$renewal_date = $nYr . "-08-01";
|
|
$prorate = 30;
|
|
break;
|
|
}
|
|
|
|
|
|
// Check for an existing invoice
|
|
$results = db_query("SELECT * FROM invoice_header WHERE school_num = $school_num AND school_year = '$school_year' AND status IN ('Open','Paid')");
|
|
if (db_num_rows($results)) return;
|
|
|
|
$line_items = array();
|
|
$subtotal = 0;
|
|
$total = 0;
|
|
|
|
|
|
// Setup first line item
|
|
$amount = 350;
|
|
if ($school_record['system_configuration'] != 'Full') $amount = 250;
|
|
|
|
|
|
$line_items[] = array('Hot Lunches On-Line Annual Hosting Fee',$amount);
|
|
$subtotal += $amount;
|
|
|
|
// Next line item
|
|
$smallSchoolDiscount = .25;
|
|
if ($currMonth > "01" && $currMonth <= "07") {
|
|
$amount = -50;
|
|
if ($school_record['system_configuration'] != 'Full') $amount = -25;
|
|
$line_items[] = array('- Early Bird Special Pricing Offer (expires June 30, '.date("Y",time()) . ')',$amount);
|
|
$subtotal += $amount;
|
|
}
|
|
|
|
// Next line item
|
|
$amount = 0;
|
|
if ($school_record['small_school_discount'] == 'Y') {
|
|
$amount = intval($subtotal * $smallSchoolDiscount) * -1;
|
|
$line_items[] = array('- Small School Discount',$amount);
|
|
$subtotal += $amount;
|
|
}
|
|
|
|
// Next line item
|
|
$amount = 0;
|
|
if (strlen($school_record['additional_invoice_fee_text']) > 0) {
|
|
$text = $school_record['additional_invoice_fee_text'];
|
|
|
|
if ($school_record['additional_invoice_fee_type'] == 'Amount') {
|
|
$amount = $subtotal + $school_record['additional_invoice_fee_amount'];
|
|
}
|
|
else {
|
|
$amount = $subtotal * $school_record['additional_invoice_fee_amount'] / 100;
|
|
$text .= ' '.number_format($amount,1).'%';
|
|
}
|
|
|
|
$line_items[] = array($text,$amount);
|
|
$subtotal += $amount;
|
|
}
|
|
|
|
// Prorated discount
|
|
if ($prorate > 0) {
|
|
// $text = "- Partial Year Discount $prorate%";
|
|
// $amount = intval($subtotal * $prorate * -1) / 100;
|
|
|
|
// $line_items[] = array($text,$amount);
|
|
// $subtotal += $amount;
|
|
}
|
|
|
|
// Next line item
|
|
$amount = 0;
|
|
if ($school_record['reseller'] != 'hotlunch') {
|
|
$results = db_query("SELECT * FROM resellers WHERE reseller_code = '".$school_record['reseller']."'");
|
|
$reseller = db_fetch_assoc($results);
|
|
$rate = $reseller['annual_rate'];
|
|
$rname = $reseller['business_name'];
|
|
$text = $rname . " Discount";
|
|
$amount = $subtotal - $rate;
|
|
|
|
$line_items[] = array($text,$amount);
|
|
$subtotal += $amount;
|
|
}
|
|
|
|
|
|
// Define invoice defaults
|
|
$invoice_date = date("Y-m-d",time());
|
|
$due_date = date("Y-m-d",time() + 60 * 60 * 24 * 30);
|
|
$charge_gst = 'Y';
|
|
$status = 'Open';
|
|
$amount_paid = 0.00;
|
|
|
|
$gst_rate = 5;
|
|
$tax_code = "GST";
|
|
|
|
if ($school_record['country'] != 'Canada') {
|
|
$charge_gst = 'N';
|
|
$gst_rate = 0;
|
|
$tax_code = "";
|
|
}
|
|
else {
|
|
if ($school_record['charge_gst'] == 'N') {
|
|
$charge_gst = 'N';
|
|
$gst_rate = 0;
|
|
$tax_code = "";
|
|
}
|
|
}
|
|
|
|
$gst = $subtotal * $gst_rate / 100;
|
|
$total = $subtotal + $gst;
|
|
|
|
$invoice_header = new Table("invoice_header");
|
|
$invoice_items = new Table("invoice_items");
|
|
|
|
$rstatus = 'Y';
|
|
|
|
$query = $invoice_header->BuildInsert();
|
|
db_query($query);
|
|
$invoice_num = db_insert_id();
|
|
|
|
for ($i = 0; $i < count($line_items); $i++) {
|
|
$sequence = $i + 1;
|
|
$description = $line_items[$i][0];
|
|
$amount = $line_items[$i][1];
|
|
$query = $invoice_items->BuildInsert();
|
|
db_query($query);
|
|
}
|
|
|
|
include "invoices.print.php";
|
|
?>
|