145 lines
4.9 KiB
PHP
145 lines
4.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* This is the model class for table "bank_program_rates".
|
|
*
|
|
* @property string $id
|
|
* @property string $bank_program_id
|
|
* @property integer $period_min
|
|
* @property integer $period_max
|
|
* @property float $rate_percent
|
|
* @property float $first_pay_percent
|
|
* @property string $created_at
|
|
* @property string $updated_at
|
|
* @property boolean $newRecord
|
|
*/
|
|
class BankProgramRate implements ImportRecord
|
|
{
|
|
public $id;
|
|
public $bank_program_id;
|
|
public $period_min;
|
|
public $period_max;
|
|
public $rate_percent;
|
|
public $first_pay_percent;
|
|
public $created_at;
|
|
public $updated_at;
|
|
public $newRecord;
|
|
|
|
/**
|
|
* BankProgramRate constructor.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->newRecord = true;
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
try {
|
|
if ($this->newRecord) {
|
|
if (!isset($this->id)) {
|
|
throw new Exception("ID generation on php for bank_program_rates");
|
|
} else {
|
|
$sql = "INSERT INTO bank_program_rates (id, bank_program_id, created_at,
|
|
period_min, period_max, rate_percent, first_pay_percent) VALUES ('" . $this->id .
|
|
"', '" . $this->bank_program_id . "', NOW(), '" . $this->period_min .
|
|
"', '" . $this->period_max . "', '" . $this->rate_percent .
|
|
"', '" . $this->first_pay_percent . "')";
|
|
}
|
|
mysql_query($sql);
|
|
$err = mysql_errno();
|
|
if ($err > 0) {
|
|
echo mysql_error();
|
|
return false;
|
|
}
|
|
if (!isset($this->id)) {
|
|
$this->id = mysql_insert_id();
|
|
}
|
|
} else {
|
|
$sql = "UPDATE bank_program_rates SET updated_at = NOW(),
|
|
period_min = '" . $this->period_min .
|
|
"', period_max = '" . $this->period_max .
|
|
"', rate_percent = '" . $this->rate_percent .
|
|
"', first_pay_percent = '" . $this->first_pay_percent .
|
|
"', bank_program_id = '" . $this->bank_program_id .
|
|
"' WHERE id = '" . $this->id . "'";
|
|
mysql_query($sql);
|
|
$err = mysql_errno();
|
|
if ($err > 0) {
|
|
echo mysql_error();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
} catch (Exception $e) {
|
|
echo $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function getIsNewRecord()
|
|
{
|
|
return $this->newRecord;
|
|
}
|
|
|
|
public static function deleteAll($condition = '')
|
|
{
|
|
throw new Exception("deleteALL not implemented");
|
|
}
|
|
|
|
public static function className()
|
|
{
|
|
return get_called_class();
|
|
}
|
|
|
|
public static function findOne($id)
|
|
{
|
|
$sql = "SELECT * FROM bank_program_rates WHERE id='$id'";
|
|
$rez = mysql_query($sql);
|
|
if (mysql_num_rows($rez)) {
|
|
$bankProgramRate = new BankProgramRate();
|
|
$bankProgramRate->newRecord = false;
|
|
$dbObject = mysql_fetch_array($rez);
|
|
$bankProgramRate->id = $dbObject['id'];
|
|
$bankProgramRate->created_at = $dbObject['created_at'];
|
|
$bankProgramRate->updated_at = $dbObject['updated_at'];
|
|
$bankProgramRate->first_pay_percent = $dbObject['first_pay_percent'];
|
|
$bankProgramRate->rate_percent = $dbObject['rate_percent'];
|
|
$bankProgramRate->period_min = $dbObject['period_min'];
|
|
$bankProgramRate->period_max = $dbObject['period_max'];
|
|
$bankProgramRate->bank_program_id = $dbObject['bank_program_id'];
|
|
|
|
return $bankProgramRate;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static function findByProgramId($programId)
|
|
{
|
|
$sql = "SELECT * FROM bank_program_rates WHERE bank_program_id='$programId' ORDER BY rate_percent asc";
|
|
$rez = mysql_query($sql);
|
|
|
|
$bankProgramRates = array();
|
|
if (mysql_num_rows($rez)) {
|
|
while ($dbObject = mysql_fetch_assoc($rez)) {
|
|
$bankProgramRate = new BankProgramRate();
|
|
$bankProgramRate->newRecord = false;
|
|
$bankProgramRate->id = $dbObject['id'];
|
|
$bankProgramRate->created_at = $dbObject['created_at'];
|
|
$bankProgramRate->updated_at = $dbObject['updated_at'];
|
|
$bankProgramRate->first_pay_percent = $dbObject['first_pay_percent'];
|
|
$bankProgramRate->rate_percent = $dbObject['rate_percent'];
|
|
$bankProgramRate->period_min = $dbObject['period_min'];
|
|
$bankProgramRate->period_max = $dbObject['period_max'];
|
|
$bankProgramRate->bank_program_id = $dbObject['bank_program_id'];
|
|
|
|
$bankProgramRates[] = $bankProgramRate;
|
|
}
|
|
}
|
|
|
|
return $bankProgramRates;
|
|
}
|
|
|
|
} |