Joywork/import/obj/BankProgram.php
2026-05-22 21:21:54 +03:00

158 lines
5.5 KiB
PHP

<?php
/**
* This is the model class for table "bank_programs".
*
* @property string $id
* @property integer $bank_id
* @property string $name
* @property float $first_pay_percent_min
* @property float $first_pay_percent_max
* @property integer $credit_sum_min
* @property integer $credit_sum_max
* @property integer $review_period
* @property string $created_at
* @property string $updated_at
* @property boolean $newRecord
*/
class BankProgram implements ImportRecord
{
public $id;
public $bank_id;
public $name;
public $first_pay_percent_min;
public $first_pay_percent_max;
public $credit_sum_min;
public $credit_sum_max;
public $review_period;
public $created_at;
public $updated_at;
public $newRecord;
public $bank;
public $bankProgramRates;
/**
* BankProgram 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");
} else {
$sql = "INSERT INTO bank_programs (id, name, created_at,
first_pay_percent_min, first_pay_percent_max, credit_sum_min, credit_sum_max, review_period, bank_id) VALUES ('" . $this->id .
"', '" . $this->name . "', NOW(), '" . $this->first_pay_percent_min .
"', '" . $this->first_pay_percent_max . "', '" . $this->credit_sum_min .
"', '" . $this->credit_sum_max . "', '" . $this->review_period . "', '" . $this->bank_id . "')";
}
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_programs SET name = '" . $this->name . "', updated_at = NOW(),
first_pay_percent_min = '" . $this->first_pay_percent_min .
"', first_pay_percent_max = '" . $this->first_pay_percent_max .
"', credit_sum_min = '" . $this->credit_sum_min .
"', credit_sum_max = '" . $this->credit_sum_max .
"', review_period = '" . $this->review_period .
"', bank_id = '" . $this->bank_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_programs WHERE id='$id'";
$rez = mysql_query($sql);
if (mysql_num_rows($rez)) {
$bankProgram = new BankProgram();
$bankProgram->newRecord = false;
$dbObject = mysql_fetch_array($rez);
$bankProgram->id = $dbObject['id'];
$bankProgram->name = $dbObject['name'];
$bankProgram->bank_id = $dbObject['bank_id'];
$bankProgram->created_at = $dbObject['created_at'];
$bankProgram->updated_at = $dbObject['updated_at'];
$bankProgram->first_pay_percent_min = $dbObject['first_pay_percent_min'];
$bankProgram->first_pay_percent_max = $dbObject['first_pay_percent_max'];
$bankProgram->credit_sum_min = $dbObject['credit_sum_min'];
$bankProgram->credit_sum_max = $dbObject['credit_sum_max'];
$bankProgram->review_period = $dbObject['review_period'];
return $bankProgram;
}
return null;
}
public static function find($ids)
{
$sql = "SELECT * FROM bank_programs where id in ('" . implode("','", $ids) . "') ORDER BY bank_id";
$rez = mysql_query($sql);
$bankPrograms = array();
if (mysql_num_rows($rez) > 0) {
while ($dbObject = mysql_fetch_assoc($rez)) {
$bankProgram = new BankProgram();
$bankProgram->newRecord = false;
$bankProgram->id = $dbObject['id'];
$bankProgram->name = $dbObject['name'];
$bankProgram->bank_id = $dbObject['bank_id'];
$bankProgram->created_at = $dbObject['created_at'];
$bankProgram->updated_at = $dbObject['updated_at'];
$bankProgram->first_pay_percent_min = $dbObject['first_pay_percent_min'];
$bankProgram->first_pay_percent_max = $dbObject['first_pay_percent_max'];
$bankProgram->credit_sum_min = $dbObject['credit_sum_min'];
$bankProgram->credit_sum_max = $dbObject['credit_sum_max'];
$bankProgram->review_period = $dbObject['review_period'];
$bankPrograms[] = $bankProgram;
}
}
return $bankPrograms;
}
}