<?php

class InfoAlokasiPendapatanBelanja extends Phalcon\Mvc\Model
{
    /**
     *
     * @var integer
     */
    public $id;
    /**
     *
     * @var string
     */
    public $tipe_alokasi;
    /**
     *
     * @var integer
     */
    public $parent_id;
    /**
     *
     * @var string
     */
    public $kode_output;
    /**
     *
     * @var string
     */
    public $nama_output;
    /**
     *
     * @var datetime
     */
    public $created_at;
    /**
     *
     * @var datetime
     */
    public $updated_at;
    /**
     *
     * @var datetime
     */
    public $deleted_at;

    /**
     * Initialize method for model.
     */

    const TIPE_ALOKASI_PENDAPATAN = 'Pendapatan';
    const TIPE_ALOKASI_BELANJA = 'Belanja';
    
    public function initialize()
    {
        $this->setSchema('jaga');
        $this->setSource('info_alokasi_pendapatan_belanja');
    }

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

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return InfoAlokasiPendapatanBelanja[]|InfoAlokasiPendapatanBelanja|\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 InfoAlokasiPendapatanBelanja|\Phalcon\Mvc\Model\ResultInterface
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    public function toArrayDetail()
    {
        $result = $this->toArray();

        $result['parent'] = [];
        if($this->parent_id > 0) {
            $parent = InfoAlokasiPendapatanBelanja::findFirst($this->parent_id);
            if(!empty($parent)) {
                $result['parent'] = $parent->toArray();
            }
        }

        return $result;
    }
}

?>