Kohir.php 1.19 KB
<?php

/**
 * @Author: irul
 * @Date:   2019-09-20 23:11:56
 * @Last Modified by:   irul
 * @Last Modified time: 2019-10-01 23:43:20
 */

namespace Integrasi\Reklame\Base\Models;

use \Integrasi\Reklame\Base\Helper;
use \Illuminate\Database\Capsule\Manager as DB;

class Kohir extends AbstractModel
{
	protected $table = 'pad_kohir';

	// == ACCESSORS == //

	public function getKohirnoAttribute($value)
	{
		if (!Helper::sptpdExist()) {
			$qry = "select get_kohirno(?) as kohirno";
			$row = DB::select(DB::raw($qry), array($this->attributes['spt_id']));
			return $row[0]->kohirno;
		} else {
			$qry = "select get_kohirno(?) as kohirno";
			$row = DB::select(DB::raw($qry), array($this->attributes['sptpd_id']));
			return $row[0]->kohirno;
		}
	}

	// == RELATIONSHIPS == //

	/**
	 * Get the spt that owns the kohir/skpd.
	 */
	public function spt()
	{
		if (!Helper::sptpdExist()) {
			return $this->belongsTo($this->getParentNamespace() . '\Spt', 'id', 'spt_id');
		}
		return null;
	}

	/**
	 * Get the sptpd that owns the kohir/skpd.
	 */
	public function sptpd()
	{
		if (Helper::sptpdExist()) {
			return $this->belongsTo($this->getParentNamespace() . '\Sptpd', 'id', 'sptpd_id');
		}
		return null;
	}
}