<?php

/**
 * @property DesaUraianOutputPenyerapan $uraianOutput
 */
class OmspanPenyerapanDanaDesa extends \Phalcon\Mvc\Model
{

    /**
     *
     * @var integer
     */
    public $id;

    /**
     *
     * @var string
     */
    public $kode_lokasi;

    /**
     *
     * @var string
     */
    public $kode_desa;

    /**
     *
     * @var integer
     */
    public $tahun;

    /**
     *
     * @var string
     */
    public $kode_uraian_output;

    /**
     *
     * @var integer
     */
    public $volume;

    /**
     *
     * @var string
     */
    public $satuan_output;

    /**
     *
     * @var string
     */
    public $cara_pengadaan;

    /**
     *
     * @var integer
     */
    public $realisasi_tahap_1;

    /**
     *
     * @var integer
     */
    public $realisasi_tahap_2;

    /**
     *
     * @var integer
     */
    public $realisasi_tahap_3;

    /**
     *
     * @var integer
     */
    public $persentase_realisasi_tahap_1;

    /**
     *
     * @var integer
     */
    public $persentase_realisasi_tahap_2;

    /**
     *
     * @var integer
     */
    public $persentase_realisasi_tahap_3;

    /**
     *
     * @var string
     */
    public $keterangan;

    public $created_at;
    public $updated_at;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        $this->setSchema("jaga");
        $this->setSource("omspan_penyerapan_dana_desa");
        $this->belongsTo('kode_desa', '\DesaMasterDesa', 'kode_PUM', ['alias' => 'desa']);
        $this->belongsTo('kode_uraian_output', '\DesaUraianOutputPenyerapan', 'kode', ['alias' => 'uraianOutput']);
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'omspan_penyerapan_dana_desa';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return OmspanPenyerapanDanaDesa[]|OmspanPenyerapanDanaDesa|\Phalcon\Mvc\Model\ResultSetInterface
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return OmspanPenyerapanDanaDesa|\Phalcon\Mvc\Model\ResultInterface
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    public function getRealisasi(): int
    {
        $realisasi = 0;
        if (!is_null($this->realisasi_tahap_3) && $this->realisasi_tahap_3 != "" && $this->realisasi_tahap_3 > 0) {
            $realisasi = $this->realisasi_tahap_3;
        } else if (!is_null($this->realisasi_tahap_2) && $this->realisasi_tahap_2 != "" && $this->realisasi_tahap_2 > 0) {
            $realisasi = $this->realisasi_tahap_2;
        } else if (!is_null($this->realisasi_tahap_1) && $this->realisasi_tahap_1 != "" && $this->realisasi_tahap_1 > 0) {
            $realisasi = $this->realisasi_tahap_1;
        }

        return $realisasi;
    }

}
