class PenaltyCalculation{
public $mDeadLineMonth = 0;
public $mDeadLineDay = 0;
public $mDeadLineYear = 0;
public $mFiledMonth = 0;
public $mFiledDay = 0;
public $mFiledYear = 0;
public $mAmountOwed = 0;
public $mFailureToFilePenalty = 0;
public $mFailureToPayPenalty = 0;
public $mInterestPenalty = 0;
public $mFiledBoolean = false;
public $mErrors = array();
private $_mYearInterestRate = 0.04;
private $_mDateNow = '0000-00-00';
private $_mDeadLineDate = '0000-00-00';
private $_mFiledDate = '0000-00-00';
public function __construct(){
$monthOptions = array( 'min_range' => 0,
'max_range' => 11
);
$this->_mDeadLineDate = new DateTime( $this->_mDeadLineDate );
$this->_mFiledDate = new DateTime( $this->_mFiledDate );
$this->setDateNow( Date('Y-m-d') );
if( isset( $_POST['deadline-year'] ) ){
$this->mDeadLineYear = filter_var( $_POST['deadline-year'], FILTER_SANITIZE_NUMBER_INT );
$this->mDeadLineYear = filter_var( $this->mDeadLineYear, FILTER_VALIDATE_INT, $yearOptions );
if( false === $this->mDeadLineYear ){
$this->mErrors[] = 'DeadLineYear';
}
}
if( isset( $_POST['amount-owed'] ) ){
$this->mAmountOwed = filter_var( $_POST['amount-owed'], FILTER_SANITIZE_NUMBER_FLOAT );
$this->mAmountOwed = filter_var( $this->mAmountOwed, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND );
if( false === $this->mAmountOwed || 0 == $this->mAmountOwed ){
$this->mErrors[] = 'You did not enter an amount owed.';
}else if( 6 < strlen( (string)$this->mAmountOwed ) ){
$this->mErrors[] = 'Do not enter more than six numbers.';
}
}
if( 0 != ( $this->mDeadLineYear ) ){
if( false == checkdate( '04', '15', $this->mDeadLineYear ) ){
$this->mErrors[] = 'DeadLineDate is not set';
}else{
$t = $this->mDeadLineYear . '-' . '04' . '-' . '15';
$this->_mDeadLineDate = new DateTime( $t );
}
}
$this->_mFiledDate = new DateTime( date('Y-m-d') );
}
public function init(){
if( ( 0 != $this->mAmountOwed ) && ( 0 != $this->_mDeadLineDate->getTimestamp() ) && ( 0 != $this->_mFiledDate->getTimestamp() ) ){
$this->mFailureToFilePenalty = $this->failureToFilePenalty( $this->mAmountOwed, $this->_mDeadLineDate, $this->_mFiledDate );
$this->mFailureToPayPenalty = $this->failureToPayPenalty( $this->mAmountOwed, $this->_mDeadLineDate, $this->_mFiledDate );
$this->mInterestPenalty = $this->interestPenalty( $this->mAmountOwed, $this->_mDeadLineDate, $this->_mYearInterestRate );
}
}
public function setInterestRate( $int ){
$this->_mYearInterestRate = $int;
}
public function getInterestRate(){
return $this->_mYearInterestRate;
}
public function setDateNow( $dateNow ){
$this->_mDateNow = new DateTime( $dateNow );
}
public function getDateNow(){
return $this->_mDateNow;
}
private function failureToFilePenalty( $amountOwed, $deadlineDate, $filedDate ){
$interval = $deadlineDate->diff( $filedDate );
$penaltyMonths = ($interval->y * 12) + $interval->m;
if( 0 < $interval->d ){
$penaltyMonths++;
}
if( 5 > $penaltyMonths ){
return ( $penaltyMonths * $amountOwed * 0.05 );
}else{
return ( $amountOwed * 0.25 );
}
}
private function failureToPayPenalty( $amountOwed, $deadlineDate, $filedDate){
$interval = $deadlineDate->diff( $filedDate );
$penaltyMonths = ($interval->y * 12) + $interval->m;
if( 0 < $interval->d ){
$penaltyMonths++;
}
return ( $amountOwed * $penaltyMonths * 0.005 );
}
private function interestPenalty( $amountOwed, $paymentDate, $yearIntRate ){
$dailyIntRate = ( $yearIntRate/365 );
$dateNow = $this->getDateNow();
$interval = $dateNow->diff( $paymentDate );
return ( $amountOwed * $interval->days * $dailyIntRate );
}
}