<?php

namespace nota\models;

use Yii;

class KasirPengeluaran extends \yii\db\ActiveRecord
{
    public static function getDb()
    {
        return Yii::$app->get('dbnota');
    }

    public static function tableName()
    {
        return 'kasir_pengeluaran';
    }

    public function rules()
    {
        return [
            [['shift_id','jumlah'], 'required'],
            [['shift_id','user_id'], 'integer'],
            [['jumlah'], 'number'],
            [['tanggal'], 'safe'],
            [['keterangan'], 'string', 'max' => 255],
        ];
    }

    public function beforeSave($insert)
    {
        if ($insert) {
            $this->tanggal = date('Y-m-d H:i:s');
        }

        return parent::beforeSave($insert);
    }

    public function getShift()
    {
        return $this->hasOne(KasirShift::class, ['id'=>'shift_id']);
    }
}