Kohir.php
1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?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;
}
}