Jump to content

Problem with clas(es) not working - I need your help


rjwelte

Recommended Posts

Page completely blanks out - nothing shows up, not even the error handling.  >:(

[code]
<?php

class Exception {
    public function __construct();

final public getMessage();
final public getCode();
final public getFile();
final public getLine();

public $message;
public $code;
public $file;
public $line;

}

class NullHandleException extends Exception {
    public function __construct($message)
    {
        parent::__construct($message);
    }
}

class Paydate_Calculator {

###
# __construct
# we set all the class variables here
###    
    public function __construct($fund_day, $holiday_array, $pay_span, $pay_day, $direct_deposit)
    {
$this->fund_day = $fund_day;
$this->holiday_array = $holiday_array;
$this->pay_span = $pay_span;
$this->pay_day = $pay_day;
$this->direct_deposit = $direct_deposit;
    }

###
# setDueDate
# takes the orginal date of the loan and adds 10 days to set the 1st due date
# then we determine how many intervals there are from then until today
# We  then keep adding ten days per loop to he orginal due date until we are
# current with today.
###
public function setDueDate() {
// now
$now = time();
//Set 1st Due Date
$original_due_date = $this->fund_day + TENDAYS;
// if due_date occured before today calculate next due_date
While ($original_due_date < $now) {
$this->due_date = $original_due_date + TENDAYS;
}

if ($this->fund_day == NULL} {
throw new NullHandleException("fund_day is null");
}
}

###
# Calculate_Due_Date
# we then set 1st due date to fund_day + pay_span and make it current
# we now fine tune the pay date for weekends and holidays
# returning true or false if this waas accomplished
# We catch all thrown error and print them to the page.
###
public function Calculate_Due_Date() {

try
{
// set 1st due date to fund_day + pay_span and make it current
setDueDate();
tunePayDay();
if ($this->pay_day >= $this->due_date) {
return 1;
} else {
$this->pay_day = $this->pay_day + $this->pay_span;
Calculate_Due_Date();
}
} catch (NullHandleException $exception) {
print $exception->getMessage();
print " in file " . $exception->getFile();
print " on line " . $exception->getLine() . "\n";

} catch (Exception $exception) {
print $exception->getMessage();
    print " in file " . $exception->getFile();
    print " on line " . $exception->getLine() . "\n";
}
}

###
# tunePayDay
# if the client does not desire direct deposit, we add 10 days to the date
# we then call Weekend() to determine if its a saturday
# we again call Weekend() to determine if its a sunday
# finally we check if it's a Holiday
###
public function tunePayDay() {

// check if direct_deposit is no, Loop forward
if (!$this->direct_deposit)
LoopType("Forward");
// check if Saturday if yes, Loop forward
if (date('D',$this->pay_day) == "Sat")
LoopType("Forward");
// check if Sunday if yes, Loop forward
if (date('D',$this->pay_day) == "Sun")
LoopType("Forward");
// Loop through holiday array and adjust pay_day according
for ($i = 0; $i < count($this->holiday_array); $i++) {
// add one more day if holiday occurs on a Monday
if ((date("D",$this->pay_day) == "Mon") && ($this->pay_day == $this->holiday_array[$i])) {
LoopType("Forward");
} else {
LoopType("Reverse");
}
}

if($this->direct_deposit == NULL) {
throw new NullHandleException("direct_deposit is null");
}

if($this->holiday_array == NULL) {
throw new NullHandleException("holiday_array is null");
}
}

###
# LoopType
# adds a day or subtracts a day to the payday date depending on
# whether we recieve "Forward" or "Reverse" as its argument
###
private function LoopType($type) {

switch ($type) {
case "Forward":
$this->pay_day = $this->pay_day + DAY;
break;

case "Reverse":
$this->pay_day = $this->pay_day - DAY;
break;
}

if($type == NULL) {
throw new NullHandleException("type is NULL");
}

}

###
# Get_due_date
# I added this to try and test whether the due date is being set 
###
public function Get_due_date() {
return $this->due_date;
}

###
# Get_pay_day
# I added this to try and test whether the pay_day is being set 
###
public function Get_pay_day() {
return $this->due_date;
}

define("DAY",    (1*24*60*60));
define("TENDAYS",    (10*24*60*60));
public $fund_day, $holiday_array, $due_date;
public $pay_span, $pay_day, $direct_deposit;
}

$fund_day = strtotime("12/15/2005");
// setup holiday array
$holiday_array[0] = strtotime("1/1/2006");
$holiday_array[1] = strtotime("1/16/2006");
$holiday_array[2] = strtotime("2/20/2006");
$holiday_array[3] = strtotime("5/29/2006");
$holiday_array[4] = strtotime("7/4/2006");
$holiday_array[5] = strtotime("9/4/2006");
$holiday_array[6] = strtotime("10/9/2006");
$holiday_array[7] = strtotime("11/11/2006");
$holiday_array[8] = strtotime("11/23/2006");
$holiday_array[9] = strtotime("12/25/2006");

//setup pay_span
$pay_span =  (7*24*60*60); //weekly (7*24*60*60),bi-weekly (14*24*60*60),monthly(30*24*60*60)

// setup $pay_day
$now = time();

// calculaate latest pay_day = fund_day + (#pay_span intervals between fund_day and present * pay_span)
$pay_day = $fund_day + strtotime(((int)$now/$pay_span) * $this->pay_span);

//setup direct deposit false = 0
$direct_deposit = 0;

$obj = new Paydate_Calculator($fund_day, $holiday_array, $pay_span, $pay_day, $direct_deposit);
$obj->Calculate_Due_Date();
print "due_date is: " . $obj->Get_due_date();
print "pay_day is: " . $obj->Get_pay_day();

?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.