2019-06-21 18:05:58 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace common\models;
|
|
|
|
|
|
|
|
use common\classes\Debug;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the model class for table "company".
|
|
|
|
*
|
|
|
|
* @property int $id
|
|
|
|
* @property int $type
|
|
|
|
* @property int $summ
|
|
|
|
* @property int $dt_add
|
|
|
|
*/
|
|
|
|
class Balance extends \yii\db\ActiveRecord
|
|
|
|
{
|
2019-06-25 12:37:09 +03:00
|
|
|
const TYPE_ACTIVE = 1;
|
|
|
|
const TYPE_PASSIVE = 0;
|
|
|
|
|
|
|
|
public static function getTypeName($id)
|
|
|
|
{
|
|
|
|
return self::getTypeList()[$id];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getTypeList()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
self::TYPE_ACTIVE => 'Актив',
|
|
|
|
self::TYPE_PASSIVE => 'Пассив',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-06-21 18:05:58 +03:00
|
|
|
public static function tableName()
|
|
|
|
{
|
2019-06-25 12:37:09 +03:00
|
|
|
return 'balance';
|
2019-06-21 18:05:58 +03:00
|
|
|
}
|
|
|
|
|
2019-06-25 12:37:09 +03:00
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[['type', 'summ', 'dt_add'], 'integer'],
|
|
|
|
];
|
|
|
|
}
|
2019-06-21 18:05:58 +03:00
|
|
|
|
2019-06-25 12:37:09 +03:00
|
|
|
public function attributeLabels()
|
|
|
|
{
|
2019-06-21 18:05:58 +03:00
|
|
|
return [
|
2019-06-25 12:37:09 +03:00
|
|
|
'id' => 'id',
|
|
|
|
'type' => 'Тип',
|
|
|
|
'summ' => 'Сумма',
|
|
|
|
'dt_add' => 'Дата добавления',
|
2019-06-21 18:05:58 +03:00
|
|
|
];
|
2019-06-25 12:37:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
2019-06-21 18:05:58 +03:00
|
|
|
|
2019-06-25 12:37:09 +03:00
|
|
|
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
|
|
|
|
}
|
2019-06-21 18:05:58 +03:00
|
|
|
}
|