<?php

namespace nota\models;

use Yii;
use yii\behaviors\BlameableBehavior;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "m_metodepembayaran".
 *
 * @property int $iId
 * @property string $vNama
 * @property int $iCabangid
 * @property string $eDeleted
 * @property int $iCreatedid
 * @property string $tCreated
 * @property string $tUpdated
 * @property int $iUpdatedid
 */
class Metodepembayaran extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function getDb()
    {
        return Yii::$app->get('dbnota');
    }
    
    public static function tableName()
    {
        return 'm_metodepembayaran';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['vNama','cabang'], 'required'],
            [['iCabangid', 'iCreatedid', 'iUpdatedid'], 'integer'],
            [['eDeleted'], 'string'],
            [['tCreated', 'tUpdated'], 'safe'],
            [['vNama'], 'string', 'max' => 100],
            [['cabang'], 'safe'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'iId' => 'ID',
            'vNama' => 'Metode Pembayaran',
            'iCabangid' => 'Cabang',
            'eDeleted' => 'Deleted',
            'iCreatedid' => 'Created',
            'tCreated' => 'Tgl. Create',
            'tUpdated' => 'Updated',
            'iUpdatedid' => 'Tgl. Update',
            'cabang' => 'Cabang',
        ];
    }
	
	public function getUsercreated(){
        //return $this->hasOne(User::className(), ['id' => 'iCreatedid']);
        return $this->hasOne(User::className(), ['ID' => 'iCreatedid']);
    }

    public function getUserupdated(){
        //return $this->hasOne(User::className(), ['id' => 'iUpdatedid']);
        return $this->hasOne(User::className(), ['ID' => 'iUpdatedid']);
    }

	public function getCabang()
    {
        return $this->hasOne(Cabang::className(), ['iId' => 'iCabangid']);
    }

	public function behaviors()
    {
    return [
                [
                    'class' => BlameableBehavior::className(),
                    'createdByAttribute' => 'iCreatedid',
                    'updatedByAttribute' => 'iUpdatedid',

                 ],
                 
                [
                    'class' => TimestampBehavior::className(),
                    'createdAtAttribute' => 'tCreated',
                    'updatedAtAttribute' => 'tUpdated',
                    'value' => new \yii\db\Expression('NOW()'),

                ],
                
        ];
    
    }
}
