<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

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

/**
 * Class DataKreditMaster
 *
 * @property string $rekening
 * @property int|null $proposal_id
 * @property string $anggota_id
 * @property int $produk_id
 * @property int $plafon
 * @property float $suku_bunga
 * @property int $jkw
 * @property Carbon|null $tgl_mulai
 * @property Carbon|null $tgl_jatuh_tempo
 * @property Carbon|null $tgl_tutup
 * @property string $nomor_pk
 * @property int $bakidebet
 * @property int $kolektibilitas
 * @property int|null $created_by
 * @property int|null $updated_by
 * @property int $status
 * @property float $angsuran_pokok
 * @property float $angsuran_bunga
 *
 * @property DataAnggotaMaster $data_anggota_master
 * @property DataKreditProduk $data_kredit_produk
 * @property Collection|DataKreditAngsuran[] $data_kredit_angsurans
 * @property Collection|DataKreditTransAngsuran[] $data_kredit_trans_angsurans
 * @property Collection|DataKreditTransRealisasi[] $data_kredit_trans_realisasis
 *
 * @package App\Models
 */
class Kredit extends Model
{
    use SoftDeletes;

    protected $table = 'data_kredit_master';
    protected $primaryKey = 'rekening';
    public $incrementing = false;
    public $timestamps = false;

    protected $casts = [
        'proposal_id' => 'int',
        'produk_id' => 'int',
        'plafon' => 'int',
        'suku_bunga' => 'float',
        'jkw' => 'int',
        'tgl_mulai' => 'datetime',
        'tgl_jatuh_tempo' => 'datetime',
        'tgl_tutup' => 'datetime',
        'bakidebet' => 'int',
        'kolektibilitas' => 'int',
        'created_by' => 'int',
        'updated_by' => 'int',
        'status' => 'int',
        'angsuran_pokok' => 'float',
        'angsuran_bunga' => 'float'
    ];

    protected $fillable = [
        'proposal_id',
        'anggota_id',
        'produk_id',
        'plafon',
        'suku_bunga',
        'jkw',
        'tgl_mulai',
        'tgl_jatuh_tempo',
        'tgl_tutup',
        'nomor_pk',
        'bakidebet',
        'kolektibilitas',
        'created_by',
        'updated_by',
        'status',
        'angsuran_pokok',
        'angsuran_bunga'
    ];

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

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

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

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

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