new balance
This commit is contained in:
@ -15,31 +15,75 @@ use common\classes\Debug;
|
||||
*/
|
||||
class Balance extends \yii\db\ActiveRecord
|
||||
{
|
||||
public static function tableName()
|
||||
const TYPE_ACTIVE = 1;
|
||||
const TYPE_PASSIVE = 0;
|
||||
|
||||
public static function getTypeName($id)
|
||||
{
|
||||
return 'balance';
|
||||
return self::getTypeList()[$id];
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['type', 'summ', 'dt_add'], 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
public function attributeLabels()
|
||||
{
|
||||
public static function getTypeList()
|
||||
{
|
||||
return [
|
||||
'id' => 'id',
|
||||
'type' => 'Тип',
|
||||
'summ' => 'Сумма',
|
||||
'dt_add' => 'Дата добавления',
|
||||
self::TYPE_ACTIVE => 'Актив',
|
||||
self::TYPE_PASSIVE => 'Пассив',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function afterFind()
|
||||
{
|
||||
parent::afterFind(); // TODO: Change the autogenerated stub
|
||||
$this->dt_add = date('d-m-Y',$this->dt_add);
|
||||
}
|
||||
public static function tableName()
|
||||
{
|
||||
return 'balance';
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['type', 'summ', 'dt_add'], 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'id',
|
||||
'type' => 'Тип',
|
||||
'summ' => 'Сумма',
|
||||
'dt_add' => 'Дата добавления',
|
||||
];
|
||||
}
|
||||
|
||||
public function afterFind()
|
||||
{
|
||||
parent::afterFind(); // TODO: Change the autogenerated stub
|
||||
$this->dt_add = date('d-m-Y', $this->dt_add);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getFieldsValues()
|
||||
{
|
||||
return $this->hasMany(FieldsValueNew::class, ['item_id' => 'id', 'item_type' => FieldsValueNew::TYPE_BALANCE]);
|
||||
}
|
||||
|
||||
public function afterSave($insert, $changedAttributes)
|
||||
{
|
||||
$post = \Yii::$app->request->post('Balance');
|
||||
|
||||
FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_BALANCE]);
|
||||
|
||||
foreach ($post['fields'] as $item) {
|
||||
$fildsValue = new FieldsValueNew();
|
||||
$fildsValue->field_id = $item['field_id'];
|
||||
$fildsValue->value = $item['value'];
|
||||
$fildsValue->order = $item['order'];
|
||||
$fildsValue->item_id = $this->id;
|
||||
$fildsValue->item_type = FieldsValueNew::TYPE_BALANCE;
|
||||
|
||||
$fildsValue->save();
|
||||
}
|
||||
|
||||
parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
|
||||
}
|
||||
}
|
65
common/models/FieldsValueNew.php
Normal file
65
common/models/FieldsValueNew.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "fields_value_new".
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $field_id
|
||||
* @property int $item_id
|
||||
* @property int $item_type
|
||||
* @property int $order
|
||||
* @property string $value
|
||||
*/
|
||||
class FieldsValueNew extends \yii\db\ActiveRecord
|
||||
{
|
||||
const TYPE_PROFILE = 0;
|
||||
const TYPE_PROJECT = 1;
|
||||
const TYPE_COMPANY = 2;
|
||||
const TYPE_BALANCE = 3;
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'fields_value_new';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['field_id', 'item_id', 'item_type'], 'required'],
|
||||
[['field_id', 'item_id', 'item_type', 'order'], 'integer'],
|
||||
[['value'], 'string'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'field_id' => 'Field ID',
|
||||
'item_id' => 'Item ID',
|
||||
'item_type' => 'Item Type',
|
||||
'order' => 'Order',
|
||||
'value' => 'Value',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getField()
|
||||
{
|
||||
return $this->hasOne(AdditionalFields::class, ['id' => 'field_id']);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user