<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Deposito extends Model
{
    use SoftDeletes;

    protected $table = 'data_deposito_master';
    protected $primaryKey = 'rekening';
    protected $keyType = 'string';
    public $incrementing = false;

    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(ProdukDeposito::class, 'produk_id');
    }

    public function tabungan()
    {
        return $this->belongsTo(Tabungan::class, 'rekening_tabungan', 'rekening')->with('anggota');
    }

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