<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

/**
 * Class DataTabunganMaster
 *
 * @property string $rekening
 * @property string $anggota_id
 * @property int $saldo
 * @property int $produk_id
 * @property Carbon $tgl_buka
 * @property Carbon $tgl_tutup
 * @property int|null $updated_by
 * @property int|null $created_by
 * @property int|null $deleted_by
 * @property int $status
 *
 * @property DataAnggotaMaster $data_anggota_master
 * @property DataTabunganProduk $data_tabungan_produk
 * @property Collection|DataTabunganTran[] $data_tabungan_trans
 *
 * @package App\Models
 */
class Tabungan extends Model
{
    protected $table = 'data_tabungan_master';
    protected $primaryKey = 'rekening';
    public $incrementing = false;
    protected $keyType = 'string';

    protected $casts = [
        'saldo' => 'int',
        'produk_id' => 'int',
        'tgl_buka' => 'datetime',
        'tgl_tutup' => 'datetime',
        'updated_by' => 'int',
        'created_by' => 'int',
        'deleted_by' => 'int',
        'status' => 'int'
    ];

    protected $guarded = [];

    public function anggota()
    {
        return $this->belongsTo(Anggota::class, 'anggota_id');
    }

    public function produk()
    {
        return $this->belongsTo(ProdukTabungan::class, 'produk_id');
    }

    public function transaksi()
    {
        return $this->hasMany(TransaksiTabungan::class, 'rekening');
    }
}
